aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomas Popela <tpopela@redhat.com>2014-06-30 20:17:58 +0800
committerTomas Popela <tpopela@redhat.com>2014-06-30 20:36:24 +0800
commit246232233d44f37271e7a9d71d4303545bafa646 (patch)
tree0abdf8d3f4476a255328eccf5d3f678dc5f71ac4
parentcdeae22ae3b58b5e2ddd3c89767a051e4c04a74f (diff)
downloadgsoc2013-evolution-246232233d44f37271e7a9d71d4303545bafa646.tar
gsoc2013-evolution-246232233d44f37271e7a9d71d4303545bafa646.tar.gz
gsoc2013-evolution-246232233d44f37271e7a9d71d4303545bafa646.tar.bz2
gsoc2013-evolution-246232233d44f37271e7a9d71d4303545bafa646.tar.lz
gsoc2013-evolution-246232233d44f37271e7a9d71d4303545bafa646.tar.xz
gsoc2013-evolution-246232233d44f37271e7a9d71d4303545bafa646.tar.zst
gsoc2013-evolution-246232233d44f37271e7a9d71d4303545bafa646.zip
EHTMLEditorSelection - Correctly find the element's parent node when changing the block's format
-rw-r--r--e-util/e-html-editor-selection.c65
1 files changed, 46 insertions, 19 deletions
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c
index 06cea06b9b..2ddeef1047 100644
--- a/e-util/e-html-editor-selection.c
+++ b/e-util/e-html-editor-selection.c
@@ -1157,6 +1157,25 @@ create_list_element (EHTMLEditorSelection *selection,
return list;
}
+static WebKitDOMNode *
+get_list_item_node_from_child (WebKitDOMNode *child)
+{
+ WebKitDOMNode *parent = webkit_dom_node_get_parent_node (child);
+
+ while (parent && !WEBKIT_DOM_IS_HTMLLI_ELEMENT (parent))
+ parent = webkit_dom_node_get_parent_node (parent);
+
+ return parent;
+}
+
+static WebKitDOMNode *
+get_list_node_from_child (WebKitDOMNode *child)
+{
+ WebKitDOMNode *parent = get_list_item_node_from_child (child);
+
+ return webkit_dom_node_get_parent_node (parent);
+}
+
static void
format_change_list_from_list (EHTMLEditorSelection *selection,
WebKitDOMDocument *document,
@@ -1178,7 +1197,7 @@ format_change_list_from_list (EHTMLEditorSelection *selection,
new_list = create_list_element (selection, document, to, 0, html_mode);
/* Copy elements from previous block to list */
- item = webkit_dom_node_get_parent_node (
+ item = get_list_item_node_from_child (
WEBKIT_DOM_NODE (selection_start_marker));
source_list = webkit_dom_node_get_parent_node (item);
current_list = source_list;
@@ -1642,6 +1661,21 @@ get_citation_level (WebKitDOMNode *node)
return level;
}
+static WebKitDOMNode *
+get_parent_block_node_from_child (WebKitDOMNode *node)
+{
+ WebKitDOMNode *parent = webkit_dom_node_get_parent_node (node);
+
+ if (element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-temp-text-wrapper") ||
+ WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (parent) ||
+ element_has_tag (WEBKIT_DOM_ELEMENT (parent), "b") ||
+ element_has_tag (WEBKIT_DOM_ELEMENT (parent), "i") ||
+ element_has_tag (WEBKIT_DOM_ELEMENT (parent), "u"))
+ parent = webkit_dom_node_get_parent_node (parent);
+
+ return parent;
+}
+
static void
format_change_block_to_block (EHTMLEditorSelection *selection,
EHTMLEditorSelectionBlockFormat format,
@@ -1688,10 +1722,8 @@ format_change_block_to_block (EHTMLEditorSelection *selection,
NULL);
}
- block = webkit_dom_node_get_parent_node (
+ block = get_parent_block_node_from_child (
WEBKIT_DOM_NODE (selection_start_marker));
- if (element_has_class (WEBKIT_DOM_ELEMENT (block), "-x-evo-temp-text-wrapper"))
- block = webkit_dom_node_get_parent_node (block);
html_mode = e_html_editor_view_get_html_mode (view);
@@ -1714,8 +1746,7 @@ format_change_block_to_block (EHTMLEditorSelection *selection,
after_selection_end = webkit_dom_node_contains (
block, WEBKIT_DOM_NODE (selection_end_marker));
- next_block = webkit_dom_node_get_next_sibling (
- WEBKIT_DOM_NODE (block));
+ next_block = webkit_dom_node_get_next_sibling (block);
if (format == E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_PARAGRAPH)
element = e_html_editor_selection_get_paragraph_element (
@@ -1817,10 +1848,8 @@ format_change_block_to_list (EHTMLEditorSelection *selection,
NULL);
}
- block = webkit_dom_node_get_parent_node (
+ block = get_parent_block_node_from_child (
WEBKIT_DOM_NODE (selection_start_marker));
- if (element_has_class (WEBKIT_DOM_ELEMENT (block), "-x-evo-temp-text-wrapper"))
- block = webkit_dom_node_get_parent_node (block);
list = create_list_element (selection, document, format, 0, html_mode);
@@ -1945,17 +1974,14 @@ format_change_list_to_list (EHTMLEditorSelection *selection,
selection_end_marker = webkit_dom_document_query_selector (
document, "span#-x-evo-selection-end-marker", NULL);
- current_list = webkit_dom_node_get_parent_node (
- webkit_dom_node_get_parent_node (
- WEBKIT_DOM_NODE (selection_start_marker)));
+ current_list = get_list_node_from_child (
+ WEBKIT_DOM_NODE (selection_start_marker));
- prev_list = webkit_dom_node_get_parent_node (
- webkit_dom_node_get_parent_node (
- WEBKIT_DOM_NODE (selection_start_marker)));
+ prev_list = get_list_node_from_child (
+ WEBKIT_DOM_NODE (selection_start_marker));
- next_list = webkit_dom_node_get_parent_node (
- webkit_dom_node_get_parent_node (
- WEBKIT_DOM_NODE (selection_end_marker)));
+ next_list = get_list_node_from_child (
+ WEBKIT_DOM_NODE (selection_end_marker));
selection_starts_in_first_child =
webkit_dom_node_contains (
@@ -2030,7 +2056,8 @@ format_change_list_to_block (EHTMLEditorSelection *selection,
selection_end = webkit_dom_document_query_selector (
document, "span#-x-evo-selection-end-marker", NULL);
- item = webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (selection_start));
+ item = get_list_item_node_from_child (
+ WEBKIT_DOM_NODE (selection_start));
source_list = webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (item));
source_list_clone = webkit_dom_node_clone_node (source_list, FALSE);