[evolution] EHTMLEditorSelection - Fix wrapping of a quoted content when editing a link inside it



commit fca1fe8f932a5f0150833c8c1f4aadb4c536b9ef
Author: Tomas Popela <tpopela redhat com>
Date:   Tue Aug 25 10:30:23 2015 +0200

    EHTMLEditorSelection - Fix wrapping of a quoted content when editing a link inside it
    
    Correctly traverse the DOM when looking for BR elements that needs to be removed and
    when looking for the last BR element that will be used as a start point when wrapping.
    Also we need to replace the hidden spaces just in that part of a paragraph that will
    be wrapped and not in the whole paragraph.

 e-util/e-html-editor-selection.c |   47 ++++++++++++++++++++++++-------------
 1 files changed, 30 insertions(+), 17 deletions(-)
---
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c
index 0863a67..5716482 100644
--- a/e-util/e-html-editor-selection.c
+++ b/e-util/e-html-editor-selection.c
@@ -6249,26 +6249,23 @@ wrap_lines (EHTMLEditorSelection *selection,
 
                        while (nd) {
                                WebKitDOMNode *next_nd = webkit_dom_node_get_next_sibling (nd);
+
+                               if (!next_nd && !webkit_dom_node_is_same_node 
(webkit_dom_node_get_parent_node (nd), block_clone))
+                                       next_nd = webkit_dom_node_get_next_sibling 
(webkit_dom_node_get_parent_node (nd));
+
                                if (WEBKIT_DOM_IS_HTMLBR_ELEMENT (nd)) {
                                        if (remove_all_br)
                                                remove_node (nd);
                                        else if (element_has_class (WEBKIT_DOM_ELEMENT (nd), 
"-x-evo-wrap-br"))
                                                remove_node (nd);
-                               }
+                               } else if (WEBKIT_DOM_IS_ELEMENT (nd) &&
+                                          webkit_dom_element_has_attribute (WEBKIT_DOM_ELEMENT (nd), 
"data-hidden-space"))
+                                       webkit_dom_html_element_set_outer_text (
+                                               WEBKIT_DOM_HTML_ELEMENT (nd), " ", NULL);
+
                                nd = next_nd;
                        }
-               }
-
-               webkit_dom_node_normalize (block_clone);
-               node = webkit_dom_node_get_first_child (block_clone);
-               if (node) {
-                       text_content = webkit_dom_node_get_text_content (node);
-                       if (g_strcmp0 ("\n", text_content) == 0)
-                               node = webkit_dom_node_get_next_sibling (node);
-                       g_free (text_content);
-               }
-
-               if (block_clone && WEBKIT_DOM_IS_ELEMENT (block_clone)) {
+               } else {
                        gint ii, length;
                        WebKitDOMNodeList *list;
 
@@ -6286,6 +6283,15 @@ wrap_lines (EHTMLEditorSelection *selection,
                        g_object_unref (list);
                }
 
+               webkit_dom_node_normalize (block_clone);
+               node = webkit_dom_node_get_first_child (block_clone);
+               if (node) {
+                       text_content = webkit_dom_node_get_text_content (node);
+                       if (g_strcmp0 ("\n", text_content) == 0)
+                               node = webkit_dom_node_get_next_sibling (node);
+                       g_free (text_content);
+               }
+
                /* We have to start from the end of the last wrapped line */
                element = webkit_dom_element_query_selector (
                        WEBKIT_DOM_ELEMENT (block_clone),
@@ -6293,14 +6299,21 @@ wrap_lines (EHTMLEditorSelection *selection,
                        NULL);
 
                if (element) {
-                       WebKitDOMNode *nd = WEBKIT_DOM_NODE (element);
+                       WebKitDOMNode *nd = webkit_dom_node_get_previous_sibling (WEBKIT_DOM_NODE (element));
+
+                       element = NULL;
+                       while (nd) {
+                               WebKitDOMNode *prev_nd = webkit_dom_node_get_previous_sibling (nd);
+
+                               if (!prev_nd && !webkit_dom_node_is_same_node 
(webkit_dom_node_get_parent_node (nd), block_clone))
+                                       prev_nd = webkit_dom_node_get_previous_sibling 
(webkit_dom_node_get_parent_node (nd));
 
-                       while ((nd = webkit_dom_node_get_previous_sibling (nd))) {
                                if (WEBKIT_DOM_IS_HTMLBR_ELEMENT (nd)) {
                                        element = WEBKIT_DOM_ELEMENT (nd);
                                        break;
-                               } else
-                                       element = NULL;
+                               }
+
+                               nd = prev_nd;
                        }
                }
 


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