summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI/TextEditor.cpp
diff options
context:
space:
mode:
authorSimonFJ20 <simonfromjakobsen@gmail.com>2022-04-12 22:46:26 +0200
committerAndreas Kling <kling@serenityos.org>2022-04-13 21:24:48 +0200
commit661e7d691e7f00f9c24f69ce4a26522e29b0ede9 (patch)
tree20c6ff770fb17be883c6a61b996433335e1cf9f9 /Userland/Libraries/LibGUI/TextEditor.cpp
parent343d69962715b494a538324694ee624d81439849 (diff)
downloadserenity-661e7d691e7f00f9c24f69ce4a26522e29b0ede9.zip
LibGUI+GMLPlayground: Replace text using ReplaceAllTextCommand
Diffstat (limited to 'Userland/Libraries/LibGUI/TextEditor.cpp')
-rw-r--r--Userland/Libraries/LibGUI/TextEditor.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp
index 6d104a0437..0ea96cc616 100644
--- a/Userland/Libraries/LibGUI/TextEditor.cpp
+++ b/Userland/Libraries/LibGUI/TextEditor.cpp
@@ -1446,6 +1446,19 @@ void TextEditor::insert_at_cursor_or_replace_selection(StringView text)
}
}
+void TextEditor::replace_all_text_while_keeping_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);
+ did_change();
+ set_cursor(normalized_range.start());
+ update();
+}
+
void TextEditor::cut()
{
if (!is_editable())