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



commit 9acc5dd3ba1c72f95fb62d3953c25856c92840b4
Author: Tomas Popela <tpopela redhat com>
Date:   Tue Oct 18 13:05:59 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.

 src/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/src/e-util/test-html-editor-units-bugs.c b/src/e-util/test-html-editor-units-bugs.c
index 6c46cca..34717e4 100644
--- a/src/e-util/test-html-editor-units-bugs.c
+++ b/src/e-util/test-html-editor-units-bugs.c
@@ -729,6 +729,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)
 {
@@ -746,4 +761,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/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 96acc9c..5f3bb17 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
@@ -796,6 +796,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]