[evolution] EHTMLEditorSelection - Avoid the possibility of having multiple selection markers



commit 7bbfe539d1c1bc951bc739252d10305840084c73
Author: Tomas Popela <tpopela redhat com>
Date:   Fri Jan 9 13:29:40 2015 +0100

    EHTMLEditorSelection - Avoid the possibility of having multiple selection markers

 e-util/e-html-editor-selection.c |   31 ++++++++++++++++++++-----------
 e-util/e-html-editor-view.c      |   17 +++++++++++++++++
 2 files changed, 37 insertions(+), 11 deletions(-)
---
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c
index 46d982f..78fdd32 100644
--- a/e-util/e-html-editor-selection.c
+++ b/e-util/e-html-editor-selection.c
@@ -2001,6 +2001,21 @@ create_selection_marker (WebKitDOMDocument *document,
 }
 
 static void
+remove_selection_markers (WebKitDOMDocument *document)
+{
+       WebKitDOMElement *marker;
+
+       marker = webkit_dom_document_get_element_by_id (
+               document, "-x-evo-selection-start-marker");
+       if (marker)
+               remove_node (WEBKIT_DOM_NODE (marker));
+       marker = webkit_dom_document_get_element_by_id (
+               document, "-x-evo-selection-end-marker");
+       if (marker)
+               remove_node (WEBKIT_DOM_NODE (marker));
+}
+
+static void
 add_selection_markers_into_element_start (WebKitDOMDocument *document,
                                           WebKitDOMElement *element,
                                           WebKitDOMElement **selection_start_marker,
@@ -2008,6 +2023,7 @@ add_selection_markers_into_element_start (WebKitDOMDocument *document,
 {
        WebKitDOMElement *marker;
 
+       remove_selection_markers (document);
        marker = create_selection_marker (document, FALSE);
        webkit_dom_node_insert_before (
                WEBKIT_DOM_NODE (element),
@@ -5924,18 +5940,9 @@ e_html_editor_selection_save (EHTMLEditorSelection *selection)
        g_object_unref (view);
 
        /* First remove all markers (if present) */
-       marker = webkit_dom_document_get_element_by_id (
-               document, "-x-evo-selection-start-marker");
-       if (marker != NULL)
-               remove_node (WEBKIT_DOM_NODE (marker));
-
-       marker = webkit_dom_document_get_element_by_id (
-               document, "-x-evo-selection-end-marker");
-       if (marker != NULL)
-               remove_node (WEBKIT_DOM_NODE (marker));
+       remove_selection_markers (document);
 
        range = html_editor_selection_get_current_range (selection);
-
        if (!range)
                return;
 
@@ -6189,8 +6196,10 @@ e_html_editor_selection_restore (EHTMLEditorSelection *selection)
        window = webkit_dom_document_get_default_view (document);
        dom_selection = webkit_dom_dom_window_get_selection (window);
        range = webkit_dom_dom_selection_get_range_at (dom_selection, 0, NULL);
-       if (!range)
+       if (!range) {
+               remove_selection_markers (document);
                return;
+       }
 
        selection_start_marker = webkit_dom_range_get_start_container (range, NULL);
        if (selection_start_marker) {
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index 5494de9..709ae82 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -386,6 +386,21 @@ create_selection_marker (WebKitDOMDocument *document,
 }
 
 static void
+remove_selection_markers (WebKitDOMDocument *document)
+{
+       WebKitDOMElement *marker;
+
+       marker = webkit_dom_document_get_element_by_id (
+               document, "-x-evo-selection-start-marker");
+       if (marker)
+               remove_node (WEBKIT_DOM_NODE (marker));
+       marker = webkit_dom_document_get_element_by_id (
+               document, "-x-evo-selection-end-marker");
+       if (marker)
+               remove_node (WEBKIT_DOM_NODE (marker));
+}
+
+static void
 add_selection_markers_into_element_start (WebKitDOMDocument *document,
                                           WebKitDOMElement *element,
                                           WebKitDOMElement **selection_start_marker,
@@ -393,6 +408,7 @@ add_selection_markers_into_element_start (WebKitDOMDocument *document,
 {
        WebKitDOMElement *marker;
 
+       remove_selection_markers (document);
        marker = create_selection_marker (document, FALSE);
        webkit_dom_node_insert_before (
                WEBKIT_DOM_NODE (element),
@@ -420,6 +436,7 @@ add_selection_markers_into_element_end (WebKitDOMDocument *document,
 {
        WebKitDOMElement *marker;
 
+       remove_selection_markers (document);
        marker = create_selection_marker (document, TRUE);
        webkit_dom_node_append_child (
                WEBKIT_DOM_NODE (element), WEBKIT_DOM_NODE (marker), NULL);


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