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



commit c071b03c99a36f8736690e6222c9db5fe488982e
Author: Tomas Popela <tpopela redhat com>
Date:   Tue Aug 25 10:46:28 2015 +0200

    Bug 753620 - Undoing the Delete operation could break the expected structure
    
    When undoing the delete operation of a selection the ended just before the anchor
    element we need to insert the deleted content before the link (in case that we
    are in the beginning of that anchor) and not in the link.

 e-util/e-html-editor-view.c |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index 2cd0b11..3a87827 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -11982,6 +11982,7 @@ undo_delete (EHTMLEditorView *view,
                e_html_editor_selection_restore (selection);
                e_html_editor_view_force_spell_check_in_viewport (view);
        } else {
+               gboolean empty_text = FALSE;
                WebKitDOMNode *nd;
 
                element = webkit_dom_document_create_element (document, "span", NULL);
@@ -12002,7 +12003,7 @@ undo_delete (EHTMLEditorView *view,
                        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 (
@@ -12010,10 +12011,25 @@ undo_delete (EHTMLEditorView *view,
                                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]