[evolution/gnome-3-30] I#104 - Replacing a string with nothing does not work in composer



commit 44cad955f0455feaa6f798895ef3fb0675708143
Author: Milan Crha <mcrha redhat com>
Date:   Wed Sep 5 14:25:00 2018 +0200

    I#104 - Replacing a string with nothing does not work in composer
    
    Closes https://gitlab.gnome.org/GNOME/evolution/issues/104

 src/e-util/test-html-editor-units-bugs.c           | 22 ++++++++++++++++++++++
 src/modules/webkit-editor/e-webkit-editor.c        |  3 ---
 .../web-extension/e-editor-dom-functions.c         |  6 +++++-
 .../web-extension/e-editor-undo-redo-manager.c     | 10 +++++++---
 4 files changed, 34 insertions(+), 7 deletions(-)
---
diff --git a/src/e-util/test-html-editor-units-bugs.c b/src/e-util/test-html-editor-units-bugs.c
index c7f669d18d..ae4a9e925f 100644
--- a/src/e-util/test-html-editor-units-bugs.c
+++ b/src/e-util/test-html-editor-units-bugs.c
@@ -1388,6 +1388,27 @@ test_issue_103 (TestFixture *fixture)
        #undef LONG_URL
 }
 
+static void
+test_issue_104 (TestFixture *fixture)
+{
+       if (!test_utils_run_simple_test (fixture,
+               "mode:plain\n"
+               "type:text to replace\n"
+               "undo:save\n"   /* 1 */
+               "seq:h\n"
+               "action:show-replace\n"
+               "type:e\t\n"
+               "type:\t\t\t\t\t\t\t\n" /* Jump to 'Replace All' */
+               "seq:n\n" /* Press it */
+               "seq:^\n" /* Close the dialog */
+               "undo:undo\n"
+               "undo:test:1\n"
+               "undo:redo\n",
+               HTML_PREFIX "<div style=\"width: 71ch;\">txt to rplac</div>" HTML_SUFFIX,
+               "txt to rplac"))
+               g_test_fail ();
+}
+
 static void
 test_issue_107 (TestFixture *fixture)
 {
@@ -1486,5 +1507,6 @@ test_add_html_editor_bug_tests (void)
        test_utils_add_test ("/bug/750636", test_bug_750636);
        test_utils_add_test ("/issue/86", test_issue_86);
        test_utils_add_test ("/issue/103", test_issue_103);
+       test_utils_add_test ("/issue/104", test_issue_104);
        test_utils_add_test ("/issue/107", test_issue_107);
 }
diff --git a/src/modules/webkit-editor/e-webkit-editor.c b/src/modules/webkit-editor/e-webkit-editor.c
index 06cd5e9541..94325e4fc1 100644
--- a/src/modules/webkit-editor/e-webkit-editor.c
+++ b/src/modules/webkit-editor/e-webkit-editor.c
@@ -2816,9 +2816,6 @@ webkit_editor_replace_all (EContentEditor *editor,
 
        wk_options |= WEBKIT_FIND_OPTIONS_WRAP_AROUND;
 
-       if (wk_editor->priv->current_text_not_found)
-               return;
-
        if (!wk_editor->priv->find_controller)
                webkit_editor_prepare_find_controller (wk_editor);
 
diff --git a/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c 
b/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c
index 098daafdcd..cf42e7a25c 100644
--- a/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c
+++ b/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c
@@ -17822,7 +17822,11 @@ e_editor_dom_selection_replace (EEditorPage *editor_page,
 
        g_clear_object (&range);
 
-       e_editor_dom_exec_command (editor_page, E_CONTENT_EDITOR_COMMAND_INSERT_TEXT, replacement);
+       if (replacement && *replacement) {
+               e_editor_dom_exec_command (editor_page, E_CONTENT_EDITOR_COMMAND_INSERT_TEXT, replacement);
+       } else {
+               e_editor_dom_exec_command (editor_page, E_CONTENT_EDITOR_COMMAND_DELETE, NULL);
+       }
 
        if (ev) {
                e_editor_dom_selection_get_coordinates (editor_page,
diff --git a/src/modules/webkit-editor/web-extension/e-editor-undo-redo-manager.c 
b/src/modules/webkit-editor/web-extension/e-editor-undo-redo-manager.c
index fab04552a1..278c73f4d2 100644
--- a/src/modules/webkit-editor/web-extension/e-editor-undo-redo-manager.c
+++ b/src/modules/webkit-editor/web-extension/e-editor-undo-redo-manager.c
@@ -1674,6 +1674,7 @@ undo_redo_replace (EEditorPage *editor_page,
                    gboolean undo)
 {
        WebKitDOMDocument *document;
+       const gchar *text;
 
        document = e_editor_page_get_document (editor_page);
 
@@ -1694,9 +1695,12 @@ undo_redo_replace (EEditorPage *editor_page,
                g_clear_object (&dom_selection);
        }
 
-       e_editor_dom_exec_command (editor_page,
-               E_CONTENT_EDITOR_COMMAND_INSERT_TEXT,
-               undo ? event->data.string.from : event->data.string.to);
+       text = undo ? event->data.string.from : event->data.string.to;
+
+       if (text && *text)
+               e_editor_dom_exec_command (editor_page, E_CONTENT_EDITOR_COMMAND_INSERT_TEXT, text);
+       else
+               e_editor_dom_exec_command (editor_page, E_CONTENT_EDITOR_COMMAND_DELETE, NULL);
 
        e_editor_dom_force_spell_check_for_current_paragraph (editor_page);
 


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