summaryrefslogtreecommitdiff
path: root/Userland/Applications
diff options
context:
space:
mode:
authorDavi <davicr38@gmail.com>2021-11-06 00:47:53 -0300
committerAndreas Kling <kling@serenityos.org>2021-11-06 12:25:15 +0100
commit0d459553fd1ad132bfb510d867d45d98e5506ec2 (patch)
tree3e8df5ff603b68561e29aeae7f386936d5f4c424 /Userland/Applications
parent60362ef401c21741573c15e327bc4f1d0b80bbcd (diff)
downloadserenity-0d459553fd1ad132bfb510d867d45d98e5506ec2.zip
TextEditor: Fix hang on "Replace All"
Diffstat (limited to 'Userland/Applications')
-rw-r--r--Userland/Applications/TextEditor/MainWidget.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/Userland/Applications/TextEditor/MainWidget.cpp b/Userland/Applications/TextEditor/MainWidget.cpp
index 76b638b755..aa506060a3 100644
--- a/Userland/Applications/TextEditor/MainWidget.cpp
+++ b/Userland/Applications/TextEditor/MainWidget.cpp
@@ -157,16 +157,18 @@ MainWidget::MainWidget()
m_replace_all_action = GUI::Action::create("Replace &All", { Mod_Ctrl, Key_F2 }, [&](auto&) {
auto needle = m_find_textbox->text();
auto substitute = m_replace_textbox->text();
+ auto length_delta = substitute.length() - needle.length();
if (needle.is_empty())
return;
if (m_use_regex)
m_editor->document().update_regex_matches(needle);
- auto found_range = m_editor->document().find_next(needle, {}, GUI::TextDocument::SearchShouldWrap::Yes, m_use_regex, m_match_case);
+ auto found_range = m_editor->document().find_next(needle, {}, GUI::TextDocument::SearchShouldWrap::No, m_use_regex, m_match_case);
while (found_range.is_valid()) {
m_editor->set_selection(found_range);
m_editor->insert_at_cursor_or_replace_selection(substitute);
- found_range = m_editor->document().find_next(needle, {}, GUI::TextDocument::SearchShouldWrap::Yes, m_use_regex, m_match_case);
+ auto next_start = GUI::TextPosition(found_range.end().line(), found_range.end().column() + length_delta);
+ found_range = m_editor->document().find_next(needle, next_start, GUI::TextDocument::SearchShouldWrap::No, m_use_regex, m_match_case);
}
});