diff options
author | Tomas Popela <tpopela@redhat.com> | 2014-06-19 20:30:34 +0800 |
---|---|---|
committer | Tomas Popela <tpopela@redhat.com> | 2014-06-19 21:23:17 +0800 |
commit | b5fa60fe93300a75b42ff1b732656c3b26a1162d (patch) | |
tree | 8c24dc9842019365f4c4e659bf45575e4b170434 | |
parent | 42a411e15437966cc1387646401ffbc7ff55f9ab (diff) | |
download | gsoc2013-evolution-b5fa60fe93300a75b42ff1b732656c3b26a1162d.tar gsoc2013-evolution-b5fa60fe93300a75b42ff1b732656c3b26a1162d.tar.gz gsoc2013-evolution-b5fa60fe93300a75b42ff1b732656c3b26a1162d.tar.bz2 gsoc2013-evolution-b5fa60fe93300a75b42ff1b732656c3b26a1162d.tar.lz gsoc2013-evolution-b5fa60fe93300a75b42ff1b732656c3b26a1162d.tar.xz gsoc2013-evolution-b5fa60fe93300a75b42ff1b732656c3b26a1162d.tar.zst gsoc2013-evolution-b5fa60fe93300a75b42ff1b732656c3b26a1162d.zip |
EHTMLEditorSelection - Don't try to save selection markers straight into body
This caused unpredictable behavior in functions, which relies on the
position of caret/selection. We won't save the selection markers and
handle the situation (no selection markers) in those functions.
-rw-r--r-- | e-util/e-html-editor-selection.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c index 5cceb09ef1..66977b4ee7 100644 --- a/e-util/e-html-editor-selection.c +++ b/e-util/e-html-editor-selection.c @@ -1659,6 +1659,36 @@ format_change_block_to_block (EHTMLEditorSelection *selection, document, "span#-x-evo-selection-start-marker", NULL); selection_end_marker = webkit_dom_document_query_selector ( document, "span#-x-evo-selection-end-marker", NULL); + + /* If the selection was not saved, move it into the first child of body */ + if (!selection_start_marker || !selection_end_marker) { + WebKitDOMHTMLElement *body; + + body = webkit_dom_document_get_body (document); + selection_start_marker = webkit_dom_document_create_element ( + document, "SPAN", NULL); + webkit_dom_element_set_id ( + selection_start_marker, "-x-evo-selection-start-marker"); + webkit_dom_node_insert_before ( + webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body)), + WEBKIT_DOM_NODE (selection_start_marker), + webkit_dom_node_get_first_child ( + webkit_dom_node_get_first_child ( + WEBKIT_DOM_NODE (body))), + NULL); + selection_end_marker = webkit_dom_document_create_element ( + document, "SPAN", NULL); + webkit_dom_element_set_id ( + selection_end_marker, "-x-evo-selection-end-marker"); + webkit_dom_node_insert_before ( + webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body)), + WEBKIT_DOM_NODE (selection_end_marker), + webkit_dom_node_get_first_child ( + webkit_dom_node_get_first_child ( + WEBKIT_DOM_NODE (body))), + NULL); + } + block = webkit_dom_node_get_parent_node ( WEBKIT_DOM_NODE (selection_start_marker)); if (element_has_class (WEBKIT_DOM_ELEMENT (block), "-x-evo-temp-text-wrapper")) @@ -1744,6 +1774,36 @@ format_change_block_to_list (EHTMLEditorSelection *selection, document, "span#-x-evo-selection-start-marker", NULL); selection_end_marker = webkit_dom_document_query_selector ( document, "span#-x-evo-selection-end-marker", NULL); + + /* If the selection was not saved, move it into the first child of body */ + if (!selection_start_marker || !selection_end_marker) { + WebKitDOMHTMLElement *body; + + body = webkit_dom_document_get_body (document); + selection_start_marker = webkit_dom_document_create_element ( + document, "SPAN", NULL); + webkit_dom_element_set_id ( + selection_start_marker, "-x-evo-selection-start-marker"); + webkit_dom_node_insert_before ( + webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body)), + WEBKIT_DOM_NODE (selection_start_marker), + webkit_dom_node_get_first_child ( + webkit_dom_node_get_first_child ( + WEBKIT_DOM_NODE (body))), + NULL); + selection_end_marker = webkit_dom_document_create_element ( + document, "SPAN", NULL); + webkit_dom_element_set_id ( + selection_end_marker, "-x-evo-selection-end-marker"); + webkit_dom_node_insert_before ( + webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body)), + WEBKIT_DOM_NODE (selection_end_marker), + webkit_dom_node_get_first_child ( + webkit_dom_node_get_first_child ( + WEBKIT_DOM_NODE (body))), + NULL); + } + block = webkit_dom_node_get_parent_node ( WEBKIT_DOM_NODE (selection_start_marker)); if (element_has_class (WEBKIT_DOM_ELEMENT (block), "-x-evo-temp-text-wrapper")) @@ -5388,6 +5448,10 @@ e_html_editor_selection_save (EHTMLEditorSelection *selection) split_node = container; } + /* Don't save selection straight into body */ + if (WEBKIT_DOM_IS_HTML_BODY_ELEMENT (split_node)) + return; + if (!split_node) { webkit_dom_node_insert_before ( container, @@ -5435,6 +5499,14 @@ e_html_editor_selection_save (EHTMLEditorSelection *selection) split_node = container; } + /* Don't save selection straight into body */ + if (WEBKIT_DOM_IS_HTML_BODY_ELEMENT (split_node)) { + marker = webkit_dom_document_get_element_by_id ( + document, "-x-evo-selection-start-marker"); + remove_node (WEBKIT_DOM_NODE (marker)); + return; + } + marker_node = WEBKIT_DOM_NODE (marker); if (split_node) { |