mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:57:43 +00:00
LibGUI: Use set_text()
for ReplaceAllTextCommand
Previously, this was reimplementing the same thing by removing all the document text and then inserting the new text - which internally would insert each code-point individually and fire change notifications for each one. This made the "Reformat GML" button very slow, since it not only had to recalculate the visual lines of the document each time, but also rebuild the preview GUI. The reason not to use `set_text()` is that it would throw away the undo stack, since it always behaved as if the text is a new document. So, let's add a parameter to disable that behaviour. This takes the time for reformatting a ~200 line GML file from several seconds, to basically instantaneous. :^)
This commit is contained in:
parent
bf1d680a75
commit
1d7d194062
3 changed files with 17 additions and 26 deletions
|
@ -1800,14 +1800,8 @@ void TextEditor::insert_at_cursor_or_replace_selection(StringView text)
|
|||
|
||||
void TextEditor::replace_all_text_without_resetting_undo_stack(StringView text)
|
||||
{
|
||||
auto start = GUI::TextPosition(0, 0);
|
||||
auto last_line_index = line_count() - 1;
|
||||
auto end = GUI::TextPosition(last_line_index, line(last_line_index).length());
|
||||
auto range = GUI::TextRange(start, end);
|
||||
auto normalized_range = range.normalized();
|
||||
execute<ReplaceAllTextCommand>(text, range, "GML Playground Format Text");
|
||||
execute<ReplaceAllTextCommand>(text, "GML Playground Format Text");
|
||||
did_change();
|
||||
set_cursor(normalized_range.start());
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue