[evolution/wip/webkit2] Bug 753620 - Undoing the Delete operation could break the expected structure



commit f87ba3ffa08ad85c28b4dbad7cb941802068e87b
Author: Tomas Popela <tpopela redhat com>
Date:   Tue Mar 1 11:06:30 2016 +0100

    Bug 753620 - Undoing the Delete operation could break the expected structure

 .../composer/e-html-editor-undo-redo-manager.c     |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/web-extensions/composer/e-html-editor-undo-redo-manager.c 
b/web-extensions/composer/e-html-editor-undo-redo-manager.c
index 7732e83..b7d4a6c 100644
--- a/web-extensions/composer/e-html-editor-undo-redo-manager.c
+++ b/web-extensions/composer/e-html-editor-undo-redo-manager.c
@@ -593,6 +593,7 @@ undo_delete (WebKitDOMDocument *document,
                dom_selection_restore (document);
                dom_force_spell_check_in_viewport (document, extension);
        } else {
+               gboolean empty_text = FALSE;
                WebKitDOMNode *nd;
 
                element = webkit_dom_document_create_element (document, "span", NULL);
@@ -614,7 +615,7 @@ undo_delete (WebKitDOMDocument *document,
                        glong length = webkit_dom_character_data_get_length (WEBKIT_DOM_CHARACTER_DATA (nd));
 
                        /* We have to preserve empty paragraphs with just UNICODE_ZERO_WIDTH_SPACE
-                        * character as when we will remove it it will collapse */
+                        * character as when we will remove it paragraph will collapse. */
                        if (length > 1) {
                                if (g_str_has_prefix (text, UNICODE_ZERO_WIDTH_SPACE))
                                        webkit_dom_character_data_replace_data (
@@ -622,10 +623,25 @@ undo_delete (WebKitDOMDocument *document,
                                else if (g_str_has_suffix (text, UNICODE_ZERO_WIDTH_SPACE))
                                        webkit_dom_character_data_replace_data (
                                                WEBKIT_DOM_CHARACTER_DATA (nd), length - 1, 1, "", NULL);
-                       }
+                       } else if (length == 0)
+                               empty_text = TRUE;
+
                        g_free (text);
                }
 
+               if (!nd || empty_text) {
+                       WebKitDOMNode *parent;
+
+                       parent = webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (element));
+                       if (WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (parent)) {
+                               webkit_dom_node_insert_before (
+                                       webkit_dom_node_get_parent_node (parent),
+                                       WEBKIT_DOM_NODE (element),
+                                       parent,
+                                       NULL);
+                       }
+               }
+
                /* Insert the deleted content back to the body. */
                webkit_dom_node_insert_before (
                        webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (element)),


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