mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-29 11:00:29 +00:00
TextEditor: Fix hang on "Replace All"
This commit is contained in:
parent
60362ef401
commit
0d459553fd
Notes:
sideshowbarker
2024-07-18 01:27:34 +09:00
Author: https://github.com/funkkiy 🔰 Commit: https://github.com/SerenityOS/serenity/commit/0d459553fd1 Pull-request: https://github.com/SerenityOS/serenity/pull/10813 Issue: https://github.com/SerenityOS/serenity/issues/10812 Reviewed-by: https://github.com/sin-ack ✅
1 changed files with 4 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue