[evolution/wip/webkit2] Bug 757887 - Reproducible freeze when deleting quoted lines in email composer



commit f1534bee4ec0048c062873159a04278739caedc2
Author: Tomas Popela <tpopela redhat com>
Date:   Wed Mar 2 17:35:54 2016 +0100

    Bug 757887 - Reproducible freeze when deleting quoted lines in email composer

 .../composer/e-html-editor-undo-redo-manager.c     |   19 ++++++++--
 .../composer/e-html-editor-view-dom-functions.c    |   38 ++++++++++++++++----
 .../composer/e-html-editor-view-dom-functions.h    |    2 +-
 3 files changed, 47 insertions(+), 12 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 92e909e..99a1959 100644
--- a/web-extensions/composer/e-html-editor-undo-redo-manager.c
+++ b/web-extensions/composer/e-html-editor-undo-redo-manager.c
@@ -656,7 +656,18 @@ undo_delete (WebKitDOMDocument *document,
                                        if (tmp_element)
                                                remove_node (WEBKIT_DOM_NODE (tmp_element));
 
-                                       dom_merge_siblings_if_necessarry (document, event->data.fragment);
+                                       dom_merge_siblings_if_necessary (document, event->data.fragment);
+
+                                       tmp_node = webkit_dom_node_get_last_child (last_child);
+                                       if (tmp_node && WEBKIT_DOM_IS_ELEMENT (tmp_node) &&
+                                           element_has_class (WEBKIT_DOM_ELEMENT (tmp_node), 
"-x-evo-quoted")) {
+                                               webkit_dom_node_append_child (
+                                                       last_child,
+                                                       WEBKIT_DOM_NODE (
+                                                               webkit_dom_document_create_element (
+                                                                       document, "br", NULL)),
+                                                       NULL);
+                                       }
 
                                        dom_remove_selection_markers (document);
 
@@ -730,7 +741,7 @@ undo_delete (WebKitDOMDocument *document,
                if (WEBKIT_DOM_IS_ELEMENT (last_child))
                        wrap_and_quote_element (document, extension, WEBKIT_DOM_ELEMENT (last_child));
 
-               dom_merge_siblings_if_necessarry (document, event->data.fragment);
+               dom_merge_siblings_if_necessary (document, event->data.fragment);
 
                dom_selection_restore (document);
                dom_force_spell_check_in_viewport (document, extension);
@@ -1917,7 +1928,7 @@ undo_redo_citation_split (WebKitDOMDocument *document,
                if (event->data.fragment &&
                    !webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (event->data.fragment))) {
                        remove_node (WEBKIT_DOM_NODE (parent));
-                       dom_merge_siblings_if_necessarry (document, NULL);
+                       dom_merge_siblings_if_necessary (document, NULL);
                        restore_selection_to_history_event_state (document, event->before);
 
                        return;
@@ -1987,7 +1998,7 @@ undo_redo_citation_split (WebKitDOMDocument *document,
                if (event->data.fragment != NULL && !in_situ)
                        undo_delete (document, extension, event);
 
-               dom_merge_siblings_if_necessarry (document, NULL);
+               dom_merge_siblings_if_necessary (document, NULL);
 
                restore_selection_to_history_event_state (document, event->before);
 
diff --git a/web-extensions/composer/e-html-editor-view-dom-functions.c 
b/web-extensions/composer/e-html-editor-view-dom-functions.c
index adbcada..71282c9 100644
--- a/web-extensions/composer/e-html-editor-view-dom-functions.c
+++ b/web-extensions/composer/e-html-editor-view-dom-functions.c
@@ -2732,14 +2732,19 @@ dom_remove_node_and_parents_if_empty (WebKitDOMNode *node)
 }
 
 void
-dom_merge_siblings_if_necessarry (WebKitDOMDocument *document,
-                                 WebKitDOMDocumentFragment *deleted_content)
+dom_merge_siblings_if_necessary (WebKitDOMDocument *document,
+                                WebKitDOMDocumentFragment *deleted_content)
 {
        gboolean equal_nodes;
+       gint ii, length;
        WebKitDOMElement *element, *prev_element;
        WebKitDOMNode *child;
+       WebKitDOMNodeList *list;
 
-       element = webkit_dom_document_query_selector (document, "blockquote + blockquote", NULL);
+       if ((element = webkit_dom_document_get_element_by_id (document, "-x-evo-main-cite")))
+               webkit_dom_element_remove_attribute (element, "id");
+
+       element = webkit_dom_document_query_selector (document, "blockquote:not([data-evo-query-skip]) + 
blockquote", NULL);
        if (!element)
                goto signature;
  repeat:
@@ -2766,13 +2771,25 @@ dom_merge_siblings_if_necessarry (WebKitDOMDocument *document,
                                        NULL);
                        remove_node (WEBKIT_DOM_NODE (prev_element));
                }
-       }
+       } else
+               webkit_dom_element_set_attribute (element, "data-evo-query-skip", "", NULL);
 
-       element = webkit_dom_document_query_selector (document, "blockquote + blockquote", NULL);
+       element = webkit_dom_document_query_selector (document, "blockquote:not([data-evo-query-skip]) + 
blockquote", NULL);
        if (element)
                goto repeat;
 
  signature:
+       list = webkit_dom_document_query_selector_all (
+               document, "blockquote[data-evo-query-skip]", NULL);
+       length = webkit_dom_node_list_get_length (list);
+       for  (ii = 0; ii < length; ii++) {
+               WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
+               webkit_dom_element_remove_attribute (
+                       WEBKIT_DOM_ELEMENT (node), "data-evo-query-skip");
+               g_object_unref (node);
+       }
+       g_object_unref (list);
+
        if (!deleted_content)
                return;
 
@@ -2913,7 +2930,7 @@ body_key_up_event_process_backspace_or_delete (WebKitDOMDocument *document,
                        NULL);
        }
 
-       dom_merge_siblings_if_necessarry (document, NULL);
+       dom_merge_siblings_if_necessary (document, NULL);
 
        dom_selection_restore (document);
        dom_force_spell_check_for_current_paragraph (document, extension);
@@ -5151,6 +5168,8 @@ dom_convert_content (WebKitDOMDocument *document,
        if (paragraph)
                webkit_dom_element_remove_attribute (paragraph, "class");
 
+       dom_merge_siblings_if_necessary (document, NULL);
+
        if (!e_html_editor_web_extension_get_html_mode (extension)) {
                dom_wrap_paragraphs_in_document (document, extension);
 
@@ -8086,7 +8105,12 @@ save_history_for_delete_or_backspace (WebKitDOMDocument *document,
 
                        node = WEBKIT_DOM_NODE (tmp_element);
                        while (!WEBKIT_DOM_IS_HTML_BODY_ELEMENT (webkit_dom_node_get_parent_node (node))) {
-                               if (webkit_dom_node_get_next_sibling (node))
+                               WebKitDOMNode *next_sibling;
+
+                               next_sibling = webkit_dom_node_get_next_sibling (node);
+                               if (next_sibling &&
+                                   (!WEBKIT_DOM_IS_HTML_BR_ELEMENT (next_sibling) ||
+                                    webkit_dom_node_get_next_sibling (next_sibling)))
                                        break;
                                node = webkit_dom_node_get_parent_node (node);
                        }
diff --git a/web-extensions/composer/e-html-editor-view-dom-functions.h 
b/web-extensions/composer/e-html-editor-view-dom-functions.h
index faa73e5..428feb3 100644
--- a/web-extensions/composer/e-html-editor-view-dom-functions.h
+++ b/web-extensions/composer/e-html-editor-view-dom-functions.h
@@ -180,7 +180,7 @@ gboolean    return_pressed_in_empty_list_item
                                                (WebKitDOMDocument *document,
                                                 EHTMLEditorWebExtension *extension,
                                                 gboolean save_history);
-void           dom_merge_siblings_if_necessarry
+void           dom_merge_siblings_if_necessary
                                                (WebKitDOMDocument *document,
                                                 WebKitDOMDocumentFragment *deleted_content);
 void           body_key_up_event_process_return_key


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