[evolution] EHTMLEditorView - Try to merge adjacent blockquotes when editing quoted text



commit ef1e7196102beaa7bfe7661882206823db97ada0
Author: Tomas Popela <tpopela redhat com>
Date:   Fri Sep 4 12:57:02 2015 +0200

    EHTMLEditorView - Try to merge adjacent blockquotes when editing quoted text
    
    When we would move the text out of the blockquote (e.g. with backspace in the
    beginning of the block) and then pressed backspace again (to append the text to
    previous block) we would end with two blockquote elements that could be merged.

 e-util/e-html-editor-view.c |  118 ++++++++++++++++++++++---------------------
 1 files changed, 61 insertions(+), 57 deletions(-)
---
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index 9a7ca86..d2cdd4d 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -3127,6 +3127,64 @@ remove_node_and_parents_if_empty (WebKitDOMNode *node)
 }
 
 static void
+merge_siblings_if_necessarry (WebKitDOMDocument *document,
+                              WebKitDOMDocumentFragment *deleted_content)
+{
+       gboolean equal_nodes;
+       WebKitDOMElement *element, *prev_element;
+       WebKitDOMNode *child;
+
+       element = webkit_dom_document_query_selector (document, "blockquote + blockquote", NULL);
+       if (!element)
+               goto signature;
+
+       prev_element = WEBKIT_DOM_ELEMENT (webkit_dom_node_get_previous_sibling (
+               WEBKIT_DOM_NODE (element)));
+       equal_nodes = webkit_dom_node_is_equal_node (
+               webkit_dom_node_clone_node (WEBKIT_DOM_NODE (element), FALSE),
+               webkit_dom_node_clone_node (WEBKIT_DOM_NODE (prev_element), FALSE));
+
+       if (equal_nodes) {
+               if (webkit_dom_element_get_child_element_count (element) >
+                   webkit_dom_element_get_child_element_count (prev_element)) {
+                       while ((child = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (element))))
+                               webkit_dom_node_append_child (
+                                       WEBKIT_DOM_NODE (prev_element), child, NULL);
+                       remove_node (WEBKIT_DOM_NODE (element));
+               } else {
+                       while ((child = webkit_dom_node_get_last_child (WEBKIT_DOM_NODE (prev_element))))
+                               webkit_dom_node_insert_before (
+                                       WEBKIT_DOM_NODE (element),
+                                       child,
+                                       webkit_dom_node_get_first_child (
+                                               WEBKIT_DOM_NODE (element)),
+                                       NULL);
+                       remove_node (WEBKIT_DOM_NODE (prev_element));
+               }
+       }
+
+ signature:
+       if (!deleted_content)
+               return;
+
+       /* Replace the corrupted signatures with the right one. */
+       element = webkit_dom_document_query_selector (
+               document, ".-x-evo-signature-wrapper + .-x-evo-signature-wrapper", NULL);
+       if (element) {
+               WebKitDOMElement *right_signature;
+
+               right_signature = webkit_dom_document_fragment_query_selector (
+                       deleted_content, ".-x-evo-signature-wrapper", NULL);
+               remove_node (webkit_dom_node_get_previous_sibling (WEBKIT_DOM_NODE (element)));
+               webkit_dom_node_replace_child (
+                       webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (element)),
+                       webkit_dom_node_clone_node (WEBKIT_DOM_NODE (right_signature), TRUE),
+                       WEBKIT_DOM_NODE (element),
+                       NULL);
+       }
+}
+
+static void
 body_keyup_event_cb (WebKitDOMElement *element,
                      WebKitDOMUIEvent *event,
                      EHTMLEditorView *view)
@@ -3311,6 +3369,7 @@ body_keyup_event_cb (WebKitDOMElement *element,
                                NULL);
                }
 
+               merge_siblings_if_necessarry (document, NULL);
                e_html_editor_selection_restore (selection);
        } else if (key_code == HTML_KEY_CODE_CONTROL)
                html_editor_view_set_links_active (view, FALSE);
@@ -11717,61 +11776,6 @@ event_selection_was_collapsed (EHTMLEditorViewHistoryEvent *ev)
 }
 
 static void
-merge_duplicates_if_necessarry (WebKitDOMDocument *document,
-                                WebKitDOMDocumentFragment *deleted_content)
-{
-       gboolean equal_nodes;
-       WebKitDOMElement *element, *prev_element;
-       WebKitDOMNode *child;
-
-       element = webkit_dom_document_query_selector (document, "blockquote + blockquote", NULL);
-       if (!element)
-               goto signature;
-
-       prev_element = WEBKIT_DOM_ELEMENT (webkit_dom_node_get_previous_sibling (
-               WEBKIT_DOM_NODE (element)));
-       equal_nodes = webkit_dom_node_is_equal_node (
-               webkit_dom_node_clone_node (WEBKIT_DOM_NODE (element), FALSE),
-               webkit_dom_node_clone_node (WEBKIT_DOM_NODE (prev_element), FALSE));
-
-       if (equal_nodes) {
-               if (webkit_dom_element_get_child_element_count (element) >
-                   webkit_dom_element_get_child_element_count (prev_element)) {
-                       while ((child = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (element))))
-                               webkit_dom_node_append_child (
-                                       WEBKIT_DOM_NODE (prev_element), child, NULL);
-                       remove_node (WEBKIT_DOM_NODE (element));
-               } else {
-                       while ((child = webkit_dom_node_get_last_child (WEBKIT_DOM_NODE (prev_element))))
-                               webkit_dom_node_insert_before (
-                                       WEBKIT_DOM_NODE (element),
-                                       child,
-                                       webkit_dom_node_get_first_child (
-                                               WEBKIT_DOM_NODE (element)),
-                                       NULL);
-                       remove_node (WEBKIT_DOM_NODE (prev_element));
-               }
-       }
-
- signature:
-       /* Replace the corrupted signatures with the right one. */
-       element = webkit_dom_document_query_selector (
-               document, ".-x-evo-signature-wrapper + .-x-evo-signature-wrapper", NULL);
-       if (element) {
-               WebKitDOMElement *right_signature;
-
-               right_signature = webkit_dom_document_fragment_query_selector (
-                       deleted_content, ".-x-evo-signature-wrapper", NULL);
-               remove_node (webkit_dom_node_get_previous_sibling (WEBKIT_DOM_NODE (element)));
-               webkit_dom_node_replace_child (
-                       webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (element)),
-                       webkit_dom_node_clone_node (WEBKIT_DOM_NODE (right_signature), TRUE),
-                       WEBKIT_DOM_NODE (element),
-                       NULL);
-       }
-}
-
-static void
 undo_delete (EHTMLEditorView *view,
             EHTMLEditorViewHistoryEvent *event)
 {
@@ -11918,7 +11922,7 @@ undo_delete (EHTMLEditorView *view,
                                        if (tmp_element)
                                                remove_node (WEBKIT_DOM_NODE (tmp_element));
 
-                                       merge_duplicates_if_necessarry (document, event->data.fragment);
+                                       merge_siblings_if_necessarry (document, event->data.fragment);
 
                                        remove_selection_markers (document);
 
@@ -11980,7 +11984,7 @@ undo_delete (EHTMLEditorView *view,
                                parent_current_block = webkit_dom_node_get_parent_node (parent_current_block);
                }
 
-               merge_duplicates_if_necessarry (document, event->data.fragment);
+               merge_siblings_if_necessarry (document, event->data.fragment);
 
                e_html_editor_selection_restore (selection);
                e_html_editor_view_force_spell_check_in_viewport (view);


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