[evolution/gnome-3-20] When pressing the Return key to end a list a new empty list is created



commit 5d32196146da919e20b77704240948ee0ad56626
Author: Tomas Popela <tpopela redhat com>
Date:   Mon Jun 27 10:44:12 2016 +0200

    When pressing the Return key to end a list a new empty list is created
    
    Also fix the remove_node_if_empty function to correctly remove empty elements.

 e-util/e-html-editor-utils.c |   44 +++++++++++++++++++++++++++++------------
 e-util/e-html-editor-view.c  |    2 +
 2 files changed, 33 insertions(+), 13 deletions(-)
---
diff --git a/e-util/e-html-editor-utils.c b/e-util/e-html-editor-utils.c
index de0b72c..ce8cb26 100644
--- a/e-util/e-html-editor-utils.c
+++ b/e-util/e-html-editor-utils.c
@@ -296,23 +296,40 @@ remove_node (WebKitDOMNode *node)
 void
 remove_node_if_empty (WebKitDOMNode *node)
 {
+       WebKitDOMNode *child;
+
        if (!WEBKIT_DOM_IS_NODE (node))
                return;
 
-       if (!webkit_dom_node_get_first_child (node)) {
-               remove_node (node);
-       } else {
-               gchar *text_content;
+       if ((child = webkit_dom_node_get_first_child (node))) {
+               WebKitDOMNode *prev_sibling, *next_sibling;
 
-               text_content = webkit_dom_node_get_text_content (node);
-               if (!text_content)
-                       remove_node (node);
+               prev_sibling = webkit_dom_node_get_previous_sibling (child);
+               next_sibling = webkit_dom_node_get_next_sibling (child);
+               /* Empty or BR as sibling, but no sibling after it. */
+               if (!webkit_dom_node_get_first_child (child) &&
+                   (!prev_sibling ||
+                    (WEBKIT_DOM_IS_HTMLBR_ELEMENT (prev_sibling) &&
+                     !webkit_dom_node_get_previous_sibling (prev_sibling))) &&
+                   (!next_sibling ||
+                    (WEBKIT_DOM_IS_HTMLBR_ELEMENT (next_sibling) &&
+                     !webkit_dom_node_get_next_sibling (next_sibling)))) {
 
-               if (text_content && !*text_content)
                        remove_node (node);
+               } else {
+                       gchar *text_content;
 
-               g_free (text_content);
-       }
+                       text_content = webkit_dom_node_get_text_content (node);
+                       if (!text_content)
+                               remove_node (node);
+
+                       if (text_content && !*text_content)
+                               remove_node (node);
+
+                       g_free (text_content);
+               }
+       } else
+               remove_node (node);
 }
 
 WebKitDOMNode *
@@ -343,11 +360,12 @@ split_node_into_two (WebKitDOMNode *item,
                while (first_child && (sibling = webkit_dom_node_get_next_sibling (first_child)))
                        webkit_dom_node_insert_before (first_child, sibling, insert_before, NULL);
 
-               while ((sibling = webkit_dom_node_get_next_sibling (tmp)))
+               while (tmp && (sibling = webkit_dom_node_get_next_sibling (tmp)))
                        webkit_dom_node_append_child (clone, sibling, NULL);
 
-               webkit_dom_node_insert_before (
-                       clone, tmp, webkit_dom_node_get_first_child (clone), NULL);
+               if (tmp)
+                       webkit_dom_node_insert_before (
+                               clone, tmp, webkit_dom_node_get_first_child (clone), NULL);
 
                prev_parent = parent;
                tmp = webkit_dom_node_get_next_sibling (parent);
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index c6320ce..2762101 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -5599,6 +5599,8 @@ return_pressed_in_empty_list_item (EHTMLEditorView *view)
 
                list = split_node_into_two (parent, -1);
 
+               remove_node_if_empty (list);
+
                if (ev) {
                        webkit_dom_node_append_child (
                                WEBKIT_DOM_NODE (fragment),


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