[evolution/wip/mcrha/webkit-jsc-api] EWebKitEditor: Prevent Replace-all to cycle indefinitely in some cases



commit f5ff389fb8b0b59315994f95a834d90651aae848
Author: Milan Crha <mcrha redhat com>
Date:   Thu Mar 5 18:36:38 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 b577dae3c8..753116e554 100644
--- a/src/modules/webkit-editor/e-webkit-editor.c
+++ b/src/modules/webkit-editor/e-webkit-editor.c
@@ -2808,7 +2808,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);
@@ -2822,6 +2825,8 @@ webkit_editor_replace_all (EContentEditor *editor,
        e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
                "EvoUndoRedo.StartRecord(EvoUndoRedo.RECORD_KIND_GROUP, %s);", "ReplaceAll");
 
+       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]