[evolution/wip/webkit-composer: 176/262] e_editor_selection_restore(): Gracefully handle no WebKitDOMRange.



commit fc4b0ea8004df39cad5d0d3733f8a161da674926
Author: Matthew Barnes <mbarnes redhat com>
Date:   Fri Feb 8 19:59:47 2013 -0500

    e_editor_selection_restore(): Gracefully handle no WebKitDOMRange.
    
    Avoid runtime warnings during composer initialization.

 e-util/e-editor-selection.c |   35 +++++++++++++++++++----------------
 1 files changed, 19 insertions(+), 16 deletions(-)
---
diff --git a/e-util/e-editor-selection.c b/e-util/e-editor-selection.c
index 5df55cc..598c7ce 100644
--- a/e-util/e-editor-selection.c
+++ b/e-util/e-editor-selection.c
@@ -2458,8 +2458,6 @@ e_editor_selection_restore (EEditorSelection *selection)
        WebKitDOMDocument *document;
        WebKitDOMRange *range;
        WebKitDOMElement *marker;
-       WebKitDOMNode *marker_node;
-       WebKitDOMNode *parent_node;
 
        g_return_if_fail (E_IS_EDITOR_SELECTION (selection));
 
@@ -2471,25 +2469,30 @@ e_editor_selection_restore (EEditorSelection *selection)
        document = webkit_web_view_get_dom_document (web_view);
        range = editor_selection_get_current_range (selection);
 
-       marker = webkit_dom_document_get_element_by_id (
-               document, "-x-evolution-selection-start-marker");
-       g_return_if_fail (marker != NULL);
+       if (range != NULL) {
+               WebKitDOMNode *marker_node;
+               WebKitDOMNode *parent_node;
 
-       marker_node = WEBKIT_DOM_NODE (marker);
-       parent_node = webkit_dom_node_get_parent_node (marker_node);
+               marker = webkit_dom_document_get_element_by_id (
+                       document, "-x-evolution-selection-start-marker");
+               g_return_if_fail (marker != NULL);
 
-       webkit_dom_range_set_start_after (range, marker_node, NULL);
-       webkit_dom_node_remove_child (parent_node, marker_node, NULL);
+               marker_node = WEBKIT_DOM_NODE (marker);
+               parent_node = webkit_dom_node_get_parent_node (marker_node);
 
-       marker = webkit_dom_document_get_element_by_id (
-               document, "-x-evolution-selection-end-marker");
-       g_return_if_fail (marker != NULL);
+               webkit_dom_range_set_start_after (range, marker_node, NULL);
+               webkit_dom_node_remove_child (parent_node, marker_node, NULL);
 
-       marker_node = WEBKIT_DOM_NODE (marker);
-       parent_node = webkit_dom_node_get_parent_node (marker_node);
+               marker = webkit_dom_document_get_element_by_id (
+                       document, "-x-evolution-selection-end-marker");
+               g_return_if_fail (marker != NULL);
 
-       webkit_dom_range_set_end_before (range, marker_node, NULL);
-       webkit_dom_node_remove_child (parent_node, marker_node, NULL);
+               marker_node = WEBKIT_DOM_NODE (marker);
+               parent_node = webkit_dom_node_get_parent_node (marker_node);
+
+               webkit_dom_range_set_end_before (range, marker_node, NULL);
+               webkit_dom_node_remove_child (parent_node, marker_node, NULL);
+       }
 
        g_object_unref (editor_widget);
 }


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