[evolution/wip/webkit-composer] EEditorSelection: If the caret is in the beginning of element swap the move direction



commit 8f9261a1e4c97aa733747ac005257e5b000cb9ed
Author: Tomas Popela <tpopela redhat com>
Date:   Fri Feb 28 10:01:15 2014 +0100

    EEditorSelection: If the caret is in the beginning of element swap the move direction

 e-util/e-editor-selection.c |   21 ++++++++++++++++-----
 e-util/e-editor-widget.c    |   10 ----------
 2 files changed, 16 insertions(+), 15 deletions(-)
---
diff --git a/e-util/e-editor-selection.c b/e-util/e-editor-selection.c
index eb916e2..ab72222 100644
--- a/e-util/e-editor-selection.c
+++ b/e-util/e-editor-selection.c
@@ -3599,7 +3599,7 @@ e_editor_selection_save_caret_position (EEditorSelection *selection)
 
        caret_node = e_editor_selection_get_caret_position_node (document);
 
-       if (WEBKIT_DOM_IS_TEXT (start_offset_node)) {
+       if (WEBKIT_DOM_IS_TEXT (start_offset_node) && start_offset != 0) {
                WebKitDOMText *split_text;
 
                split_text = webkit_dom_text_split_text (
@@ -3668,6 +3668,7 @@ e_editor_selection_restore_caret_position (EEditorSelection *selection)
        WebKitDOMDocument *document;
        WebKitDOMElement *element;
        gboolean fix_after_quoting;
+       gboolean swap_direction = FALSE;
 
        g_return_if_fail (E_IS_EDITOR_SELECTION (selection));
 
@@ -3688,6 +3689,9 @@ e_editor_selection_restore_caret_position (EEditorSelection *selection)
                WebKitDOMNode *prev_sibling;
                WebKitDOMNode *next_sibling;
 
+               if (!webkit_dom_node_get_previous_sibling (WEBKIT_DOM_NODE (element)))
+                       swap_direction = TRUE;
+
                window = webkit_dom_document_get_default_view (document);
                window_selection = webkit_dom_dom_window_get_selection (window);
                parent_node = webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (element));
@@ -3741,10 +3745,17 @@ e_editor_selection_restore_caret_position (EEditorSelection *selection)
                 * position is saved it is not on the place where it supposed
                 * to be (it is in the beginning of parent's element. It can
                 * be avoided by moving with the caret. */
-               webkit_dom_dom_selection_modify (
-                       window_selection, "move", "backward", "character");
-               webkit_dom_dom_selection_modify (
-                       window_selection, "move", "forward", "character");
+               if (swap_direction) {
+                       webkit_dom_dom_selection_modify (
+                               window_selection, "move", "forward", "character");
+                       webkit_dom_dom_selection_modify (
+                               window_selection, "move", "backward", "character");
+               } else {
+                       webkit_dom_dom_selection_modify (
+                               window_selection, "move", "backward", "character");
+                       webkit_dom_dom_selection_modify (
+                               window_selection, "move", "forward", "character");
+               }
 
                webkit_dom_node_normalize (parent_node);
        }
diff --git a/e-util/e-editor-widget.c b/e-util/e-editor-widget.c
index 975f6f4..28789be 100644
--- a/e-util/e-editor-widget.c
+++ b/e-util/e-editor-widget.c
@@ -4003,16 +4003,6 @@ convert_when_changing_composer_mode (EEditorWidget *widget)
                e_editor_selection_restore_caret_position (selection);
 
        e_editor_widget_force_spellcheck (widget);
-
-       if (restore) {
-               WebKitDOMDOMWindow *window;
-               WebKitDOMDOMSelection *dom_selection;
-
-               window = webkit_dom_document_get_default_view (document);
-               dom_selection = webkit_dom_dom_window_get_selection (window);
-               webkit_dom_dom_selection_modify (
-                       dom_selection, "move", "backward", "character");
-       }
 }
 
 /**


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