[evolution/gnome-3-22] Bug 772918 - Using keyboard shortcuts undo/redo is broken



commit 7d6afad324aedb763bc5986fe123a18835db9c0e
Author: Tomas Popela <tpopela redhat com>
Date:   Tue Oct 18 13:16:21 2016 +0200

    Bug 772918 - Using keyboard shortcuts undo/redo is broken
    
    If redoing an INPUT event that was done in the middle of the text we need to
    move one character backward as the range is pointing after the character and
    not before it - for INPUT events we don't save the before coordinates.

 e-util/test-html-editor-units-bugs.c               |   16 ++++++++++++++
 .../web-extension/e-editor-undo-redo-manager.c     |   22 ++++++++++++++++++++
 2 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/e-util/test-html-editor-units-bugs.c b/e-util/test-html-editor-units-bugs.c
index c982d2c..039d9f5 100644
--- a/e-util/test-html-editor-units-bugs.c
+++ b/e-util/test-html-editor-units-bugs.c
@@ -731,6 +731,21 @@ test_bug_772513 (TestFixture *fixture)
                g_test_fail ();
 }
 
+static void
+test_bug_772918 (TestFixture *fixture)
+{
+       if (!test_utils_run_simple_test (fixture,
+               "mode:html\n"
+               "type:a b c d\n"
+               "seq:lll\n"
+               "type:1 2 3 \n"
+               "undo:undo:6\n"
+               "undo:redo:6\n",
+               HTML_PREFIX "<div>a b 1 2 3 c d</div>" HTML_SUFFIX,
+               "a b 1 2 3 c d"))
+               g_test_fail ();
+}
+
 void
 test_add_html_editor_bug_tests (void)
 {
@@ -748,4 +763,5 @@ test_add_html_editor_bug_tests (void)
        test_utils_add_test ("/bug/771493", test_bug_771493);
        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);
 }
diff --git a/modules/webkit-editor/web-extension/e-editor-undo-redo-manager.c 
b/modules/webkit-editor/web-extension/e-editor-undo-redo-manager.c
index 3e23716..e60feb4 100644
--- a/modules/webkit-editor/web-extension/e-editor-undo-redo-manager.c
+++ b/modules/webkit-editor/web-extension/e-editor-undo-redo-manager.c
@@ -798,6 +798,28 @@ undo_delete (EEditorPage *editor_page,
                else
                        range = get_range_for_point (document, event->after.start);
 
+               /* If redoing an INPUT event that was done in the middle of the
+                * text we need to move one character backward as the range is
+                * pointing after the character and not before it - for INPUT
+                * events we don't save the before coordinates. */
+               if (event->type == HISTORY_INPUT) {
+                       glong start_offset;
+                       WebKitDOMNode *start_container;
+
+                       start_offset = webkit_dom_range_get_start_offset (range, NULL);
+                       start_container = webkit_dom_range_get_start_container (range, NULL);
+
+                       if (WEBKIT_DOM_IS_CHARACTER_DATA (start_container) &&
+                           start_offset != webkit_dom_character_data_get_length (WEBKIT_DOM_CHARACTER_DATA 
(start_container))) {
+                               webkit_dom_range_set_start (
+                                       range,
+                                       start_container,
+                                       start_offset > 0 ? start_offset - 1 : 0,
+                                       NULL);
+                               webkit_dom_range_collapse (range, TRUE, NULL);
+                       }
+               }
+
                webkit_dom_range_surround_contents (range, WEBKIT_DOM_NODE (element), NULL);
                webkit_dom_dom_selection_remove_all_ranges (dom_selection);
                webkit_dom_dom_selection_add_range (dom_selection, range);


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