[evolution/gnome-3-16] Bug 746733 - Turning off Plain text font style moves cursor by one letter



commit 56739f85cb33506502c411cb6101855416a3f504
Author: Tomas Popela <tpopela redhat com>
Date:   Thu Mar 26 11:18:57 2015 +0100

    Bug 746733 - Turning off Plain text font style moves cursor by one letter
    
    Also before this change it was impossible to turn off the font formatting
    (bold, italic, ..) in the middle of formatted text.

 e-util/e-html-editor-selection.c |   55 ++++++++++++++++++-------------------
 1 files changed, 27 insertions(+), 28 deletions(-)
---
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c
index 8f987ed..34c87d9 100644
--- a/e-util/e-html-editor-selection.c
+++ b/e-util/e-html-editor-selection.c
@@ -3074,6 +3074,29 @@ set_font_style (WebKitDOMDocument *document,
                WebKitDOMNode *node;
 
                node = webkit_dom_node_get_previous_sibling (WEBKIT_DOM_NODE (element));
+
+               /* Turning the formatting in the middle of element. */
+               if (webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (element))) {
+                       WebKitDOMNode *clone;
+                       WebKitDOMNode *sibling;
+
+                       clone = webkit_dom_node_clone_node (
+                               WEBKIT_DOM_NODE (parent), FALSE);
+
+                       while ((sibling = webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (element))))
+                               webkit_dom_node_insert_before (
+                                       clone,
+                                       sibling,
+                                       webkit_dom_node_get_first_child (clone),
+                                       NULL);
+
+                       webkit_dom_node_insert_before (
+                               webkit_dom_node_get_parent_node (parent),
+                               clone,
+                               webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (parent)),
+                               NULL);
+               }
+
                webkit_dom_node_insert_before (
                        webkit_dom_node_get_parent_node (parent),
                        WEBKIT_DOM_NODE (element),
@@ -3081,7 +3104,7 @@ set_font_style (WebKitDOMDocument *document,
                        NULL);
                webkit_dom_node_insert_before (
                        webkit_dom_node_get_parent_node (parent),
-                       WEBKIT_DOM_NODE (node),
+                       node,
                        webkit_dom_node_get_next_sibling (parent),
                        NULL);
 
@@ -4504,33 +4527,9 @@ e_html_editor_selection_set_monospaced (EHTMLEditorSelection *selection,
                        g_free (beginning);
                        g_free (end);
                } else {
-                       WebKitDOMRange *new_range;
-
-                       webkit_dom_element_set_id (tt_element, "ev-tt");
-
-                       webkit_dom_html_element_insert_adjacent_html (
-                               WEBKIT_DOM_HTML_ELEMENT (tt_element),
-                               "beforeend",
-                               UNICODE_ZERO_WIDTH_SPACE,
-                               NULL);
-
-                       /* We need to get that element again */
-                       tt_element = webkit_dom_document_get_element_by_id (
-                               document, "ev-tt");
-                       webkit_dom_element_remove_attribute (
-                               WEBKIT_DOM_ELEMENT (tt_element), "id");
-
-                       new_range = webkit_dom_document_create_range (document);
-                       webkit_dom_range_set_start_after (
-                               new_range, WEBKIT_DOM_NODE (tt_element), NULL);
-                       webkit_dom_range_set_end_after (
-                               new_range, WEBKIT_DOM_NODE (tt_element), NULL);
-
-                       webkit_dom_dom_selection_remove_all_ranges (dom_selection);
-                       webkit_dom_dom_selection_add_range (dom_selection, new_range);
-                       webkit_dom_dom_selection_modify (
-                               dom_selection, "move", "right", "character");
-                       g_object_unref (new_range);
+                       e_html_editor_selection_save (selection);
+                       set_font_style (document, "", FALSE);
+                       e_html_editor_selection_restore (selection);
                }
 
                /* Re-set formatting */


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