[evolution/wip/webkit2] EHTMLEditorView - Try to merge adjacent blockquotes when editing quoted text
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit2] EHTMLEditorView - Try to merge adjacent blockquotes when editing quoted text
- Date: Tue, 1 Mar 2016 12:43:04 +0000 (UTC)
commit cea07c47c1fa447cebf23aa1378e7737d96f14d8
Author: Tomas Popela <tpopela redhat com>
Date: Tue Mar 1 13:34:22 2016 +0100
EHTMLEditorView - Try to merge adjacent blockquotes when editing quoted text
.../composer/e-html-editor-undo-redo-manager.c | 59 +-------------------
.../composer/e-html-editor-view-dom-functions.c | 59 ++++++++++++++++++++
.../composer/e-html-editor-view-dom-functions.h | 3 +
3 files changed, 64 insertions(+), 57 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 b7d4a6c..d118fd6 100644
--- a/web-extensions/composer/e-html-editor-undo-redo-manager.c
+++ b/web-extensions/composer/e-html-editor-undo-redo-manager.c
@@ -328,61 +328,6 @@ event_selection_was_collapsed (EHTMLEditorHistoryEvent *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 (WebKitDOMDocument *document,
EHTMLEditorWebExtension *extension,
EHTMLEditorHistoryEvent *event)
@@ -526,7 +471,7 @@ undo_delete (WebKitDOMDocument *document,
if (tmp_element)
remove_node (WEBKIT_DOM_NODE (tmp_element));
- merge_duplicates_if_necessarry (document, event->data.fragment);
+ dom_merge_siblings_if_necessarry (document, event->data.fragment);
dom_remove_selection_markers (document);
@@ -588,7 +533,7 @@ undo_delete (WebKitDOMDocument *document,
parent_current_block = webkit_dom_node_get_parent_node (parent_current_block);
}
- merge_duplicates_if_necessarry (document, event->data.fragment);
+ dom_merge_siblings_if_necessarry (document, event->data.fragment);
dom_selection_restore (document);
dom_force_spell_check_in_viewport (document, extension);
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 c8f5083..b44c599 100644
--- a/web-extensions/composer/e-html-editor-view-dom-functions.c
+++ b/web-extensions/composer/e-html-editor-view-dom-functions.c
@@ -2654,6 +2654,64 @@ dom_remove_node_and_parents_if_empty (WebKitDOMNode *node)
}
}
+void
+dom_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,
@@ -2838,6 +2896,7 @@ body_keyup_event_cb (WebKitDOMElement *element,
NULL);
}
+ dom_merge_siblings_if_necessarry (document, NULL);
dom_selection_restore (document);
} else if (key_code == HTML_KEY_CODE_CONTROL)
dom_set_links_active (document, FALSE);
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 9b4ec4d..bcc9d59 100644
--- a/web-extensions/composer/e-html-editor-view-dom-functions.h
+++ b/web-extensions/composer/e-html-editor-view-dom-functions.h
@@ -177,6 +177,9 @@ gboolean return_pressed_in_empty_list_item
(WebKitDOMDocument *document,
EHTMLEditorWebExtension *extension,
gboolean save_history);
+void dom_merge_siblings_if_necessarry
+ (WebKitDOMDocument *document,
+ WebKitDOMDocumentFragment *deleted_content);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]