From 6e137c02d26df269c9860ac69e9d8824e4b5336b Mon Sep 17 00:00:00 2001 From: Ignacio Etcheverry Date: Sat, 30 Jul 2016 01:11:02 +0200 Subject: Fix infinite loop when replacing text --- tools/editor/code_editor.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/editor/code_editor.cpp b/tools/editor/code_editor.cpp index ed7a46d70d..d2bf070f1b 100644 --- a/tools/editor/code_editor.cpp +++ b/tools/editor/code_editor.cpp @@ -188,7 +188,9 @@ void FindReplaceBar::_replace_all() { text_edit->cursor_set_line(0); text_edit->cursor_set_column(0); + String replace_text=get_replace_text(); int search_text_len=get_search_text().length(); + int rc=0; replace_all_mode = true; @@ -204,7 +206,7 @@ void FindReplaceBar::_replace_all() { if (match_from < prev_match) break; // done - prev_match=match_to; + prev_match=Point2i(result_line,result_col+replace_text.length()); text_edit->select(result_line,result_col,result_line,match_to.y); @@ -214,12 +216,12 @@ void FindReplaceBar::_replace_all() { continue; // replace but adjust selection bounds - text_edit->insert_text_at_cursor(get_replace_text()); + text_edit->insert_text_at_cursor(replace_text); if (match_to.x==selection_end.x) - selection_end.y+=get_replace_text().length() - get_search_text().length(); + selection_end.y+=replace_text.length()-search_text_len; } else { // just replace - text_edit->insert_text_at_cursor(get_replace_text()); + text_edit->insert_text_at_cursor(replace_text); } rc++; -- cgit v1.2.3