[evolution] When pressing the Return key to end a list a new empty list is created



commit 6d72fb7fc92782d45996cd602a42d8e9ed3879f4
Author: Tomas Popela <tpopela redhat com>
Date:   Wed Jun 29 13:38:07 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 |   45 +++++++++++++++++++++++++++++------------
 e-util/e-html-editor-view.c  |    2 +
 2 files changed, 34 insertions(+), 13 deletions(-)
---
diff --git a/e-util/e-html-editor-utils.c b/e-util/e-html-editor-utils.c
index de0b72c..2899e92 100644
--- a/e-util/e-html-editor-utils.c
+++ b/e-util/e-html-editor-utils.c
@@ -296,23 +296,41 @@ 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;
+
+               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) &&
+                   !WEBKIT_DOM_IS_TEXT (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)))) {
 
-               text_content = webkit_dom_node_get_text_content (node);
-               if (!text_content)
                        remove_node (node);
+               } else {
+                       gchar *text_content;
 
-               if (text_content && !*text_content)
-                       remove_node (node);
+                       text_content = webkit_dom_node_get_text_content (node);
+                       if (!text_content)
+                               remove_node (node);
 
-               g_free (text_content);
-       }
+                       if (text_content && !*text_content)
+                               remove_node (node);
+
+                       g_free (text_content);
+               }
+       } else
+               remove_node (node);
 }
 
 WebKitDOMNode *
@@ -343,11 +361,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 0f073da..92658a9 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -5620,6 +5620,8 @@ return_pressed_in_empty_list_item (EHTMLEditorView *view)
                        list,
                        NULL);
 
+               remove_node_if_empty (list);
+
                if (ev) {
                        e_html_editor_selection_get_selection_coordinates (
                                selection,


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