[evolution/gnome-3-36] EWebKitEditor: Prevent Replace-all to cycle indefinitely in some cases



commit 0d47b5eb6052966dda0fd55c17693375b4256885
Author: Milan Crha <mcrha redhat com>
Date:   Fri Mar 6 10:22:14 2020 +0100

    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);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]