[evolution/gnome-3-22] Bug 773164 - copy pasting paragraphs and then undoing - redoing is broken



commit 9cac4bbb2e6fd9ebf879b4aa0241c5a8f3887df7
Author: Tomas Popela <tpopela redhat com>
Date:   Wed Oct 19 12:40:19 2016 +0200

    Bug 773164 - copy pasting paragraphs and then undoing - redoing is broken
    
    The code for saving the undo/redo history for cut was not called for the
    Ctrl-x shortcut. Also remove a WebKit's BR element if presented
    (otherwise an extra new line would be presented).

 e-util/test-html-editor-units-bugs.c               |   35 ++++++++++++++++++++
 modules/webkit-editor/e-webkit-editor.c            |    6 ++-
 .../web-extension/e-editor-dom-functions.c         |   18 ++++++++++
 3 files changed, 57 insertions(+), 2 deletions(-)
---
diff --git a/e-util/test-html-editor-units-bugs.c b/e-util/test-html-editor-units-bugs.c
index 039d9f5..14913d4 100644
--- a/e-util/test-html-editor-units-bugs.c
+++ b/e-util/test-html-editor-units-bugs.c
@@ -746,6 +746,40 @@ test_bug_772918 (TestFixture *fixture)
                g_test_fail ();
 }
 
+static void
+test_bug_773164 (TestFixture *fixture)
+{
+       test_utils_set_clipboard_text ("This is paragraph 1\n\nThis is paragraph 2\n\nThis is a longer 
paragraph 3", FALSE);
+
+       if (!test_utils_run_simple_test (fixture,
+               "mode:plain\n"
+               "undo:save\n"
+               "action:paste\n"
+               "undo:undo\n"
+               "undo:test\n"
+               "undo:redo\n"
+               "seq:huuuue\n" /* Go to the end of the first line */
+               "seq:Sdds\n"
+               "action:cut\n"
+               "seq:dde\n" /* Go to the end of the last line */
+               "action:paste\n"
+               "undo:undo:5\n"
+               "undo:test\n"
+               "undo:redo:5\n",
+               HTML_PREFIX "<div style=\"width: 71ch;\">This is paragraph 1</div>"
+               "<div style=\"width: 71ch;\"><br></div>"
+               "<div style=\"width: 71ch;\">This is a longer paragraph 3</div>"
+               "<div style=\"width: 71ch;\"><br></div>"
+               "<div style=\"width: 71ch;\">This is paragraph 2</div>"
+               HTML_SUFFIX,
+               "This is paragraph 1\n"
+               "\n"
+               "This is a longer paragraph 3\n"
+               "\n"
+               "This is paragraph 2"))
+               g_test_fail ();
+}
+
 void
 test_add_html_editor_bug_tests (void)
 {
@@ -764,4 +798,5 @@ test_add_html_editor_bug_tests (void)
        test_utils_add_test ("/bug/772171", test_bug_772171);
        test_utils_add_test ("/bug/772513", test_bug_772513);
        test_utils_add_test ("/bug/772918", test_bug_772918);
+       test_utils_add_test ("/bug/773164", test_bug_773164);
 }
diff --git a/modules/webkit-editor/e-webkit-editor.c b/modules/webkit-editor/e-webkit-editor.c
index 01081c1..633b4b6 100644
--- a/modules/webkit-editor/e-webkit-editor.c
+++ b/modules/webkit-editor/e-webkit-editor.c
@@ -5821,8 +5821,10 @@ webkit_editor_key_press_event (GtkWidget *widget,
                return TRUE;
        }
 
-       if (((event)->state & GDK_SHIFT_MASK) &&
-           ((event)->keyval == GDK_KEY_Delete)) {
+       if ((((event)->state & GDK_SHIFT_MASK) &&
+           ((event)->keyval == GDK_KEY_Delete)) ||
+           (((event)->state & GDK_CONTROL_MASK) &&
+           ((event)->keyval == GDK_KEY_x))) {
                webkit_editor_cut (E_CONTENT_EDITOR (wk_editor));
                return TRUE;
        }
diff --git a/modules/webkit-editor/web-extension/e-editor-dom-functions.c 
b/modules/webkit-editor/web-extension/e-editor-dom-functions.c
index 0154025..ee7d839 100644
--- a/modules/webkit-editor/web-extension/e-editor-dom-functions.c
+++ b/modules/webkit-editor/web-extension/e-editor-dom-functions.c
@@ -8657,6 +8657,22 @@ pasting_quoted_content (const gchar *content)
                strstr (content, "\"-x-evo-");
 }
 
+static void
+remove_apple_interchange_newline_elements (WebKitDOMDocument *document)
+{
+       gint ii;
+       WebKitDOMHTMLCollection *collection = NULL;
+
+       collection = webkit_dom_document_get_elements_by_class_name_as_html_collection (
+               document, "Apple-interchange-newline");
+       for (ii = webkit_dom_html_collection_get_length (collection); ii--;) {
+               WebKitDOMNode *node = webkit_dom_html_collection_item (collection, ii);
+
+               remove_node (node);
+       }
+       g_clear_object (&collection);
+}
+
 /*
  * e_editor_dom_insert_html:
  * @selection: an #EEditorSelection
@@ -8808,6 +8824,8 @@ e_editor_dom_insert_html (EEditorPage *editor_page,
        } else
                e_editor_dom_convert_and_insert_html_into_selection (editor_page, html_text, TRUE);
 
+       remove_apple_interchange_newline_elements (document);
+
        if (ev) {
                e_editor_dom_selection_get_coordinates (editor_page,
                        &ev->after.start.x,


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