From 2b7b2c61fb503092fa4439fdf96a56be02b6094b Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Fri, 6 Mar 2020 10:22:14 +0100 Subject: [PATCH] EWebKitEditor: Prevent Replace-all to cycle indefinitely in some cases In case the search and the replace words are similar (like changing capitals or such and searching case insensitively), the search can repeat indefinitely for replace all. This makes the Replace-all use only search from the top of the document to the bottom, without wrap around, thus it'll stop at the end of the document on its own. --- src/modules/webkit-editor/e-webkit-editor.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/modules/webkit-editor/e-webkit-editor.c b/src/modules/webkit-editor/e-webkit-editor.c index 1ff85a637b..38d5e54ea8 100644 --- a/src/modules/webkit-editor/e-webkit-editor.c +++ b/src/modules/webkit-editor/e-webkit-editor.c @@ -2843,7 +2843,10 @@ webkit_editor_replace_all (EContentEditor *editor, wk_editor = E_WEBKIT_EDITOR (editor); wk_options = find_flags_to_webkit_find_options (flags); - wk_options |= WEBKIT_FIND_OPTIONS_WRAP_AROUND; + /* Unset the two, because replace-all will be always from the beginning + of the document downwards, without wrap around, to avoid indefinite + cycle with similar search and replace words. */ + wk_options = wk_options & (~(WEBKIT_FIND_OPTIONS_BACKWARDS | WEBKIT_FIND_OPTIONS_WRAP_AROUND)); if (!wk_editor->priv->find_controller) webkit_editor_prepare_find_controller (wk_editor); @@ -2854,6 +2857,8 @@ webkit_editor_replace_all (EContentEditor *editor, wk_editor->priv->performing_replace_all = TRUE; wk_editor->priv->replaced_count = 0; + webkit_web_view_execute_editing_command (WEBKIT_WEB_VIEW (wk_editor), "MoveToBeginningOfDocumentAndModifySelection"); + webkit_find_controller_search (wk_editor->priv->find_controller, find_text, wk_options, G_MAXUINT); }