[evolution] EHTMLEditor - Fix e_html_editor_view_force_spell_check_for_current_paragraph and use it where possib



commit 7d5392d49b0337c8432bc96714f020aecf912a2b
Author: Tomas Popela <tpopela redhat com>
Date:   Mon Jul 21 13:51:13 2014 +0200

    EHTMLEditor - Fix e_html_editor_view_force_spell_check_for_current_paragraph and use it where possible
    
    Save the end node that we are using to mark the end of the paragraph
    into the right place to avoid the busy loop.
    Use e_html_editor_selection_save/restore to avoid lose of selection.

 e-util/e-html-editor-selection.c |    7 ++---
 e-util/e-html-editor-view.c      |   40 +++++++++++++++++++++++++++----------
 2 files changed, 32 insertions(+), 15 deletions(-)
---
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c
index 56d7d8b..95188e8 100644
--- a/e-util/e-html-editor-selection.c
+++ b/e-util/e-html-editor-selection.c
@@ -1984,7 +1984,6 @@ format_change_block_to_list (EHTMLEditorSelection *selection,
        merge_lists_if_possible (WEBKIT_DOM_NODE (list));
 
        e_html_editor_selection_restore (selection);
-       e_html_editor_view_force_spell_check (view);
 }
 
 static void
@@ -2253,7 +2252,7 @@ e_html_editor_selection_set_block_format (EHTMLEditorSelection *selection,
        if (!from_list && to_list)
                format_change_block_to_list (selection, format, view, document);
 
-       e_html_editor_view_force_spell_check (view);
+       e_html_editor_view_force_spell_check_for_current_paragraph (view);
 
        g_object_unref (view);
 
@@ -2836,7 +2835,7 @@ e_html_editor_selection_indent (EHTMLEditorSelection *selection)
        }
  out:
        e_html_editor_selection_restore (selection);
-       e_html_editor_view_force_spell_check (view);
+       e_html_editor_view_force_spell_check_for_current_paragraph (view);
 
        g_object_unref (view);
 
@@ -3156,7 +3155,7 @@ e_html_editor_selection_unindent (EHTMLEditorSelection *selection)
        }
  out:
        e_html_editor_selection_restore (selection);
-       e_html_editor_view_force_spell_check (view);
+       e_html_editor_view_force_spell_check_for_current_paragraph (view);
 
        g_object_unref (view);
 
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index 4bea1ab..53ca833 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -216,7 +216,8 @@ e_html_editor_view_force_spell_check_for_current_paragraph (EHTMLEditorView *vie
        WebKitDOMDocument *document;
        WebKitDOMDOMSelection *dom_selection;
        WebKitDOMDOMWindow *window;
-       WebKitDOMElement *caret, *parent, *element;
+       WebKitDOMElement *selection_start_marker, *selection_end_marker;
+       WebKitDOMElement *parent, *element;
        WebKitDOMRange *end_range, *actual;
        WebKitDOMText *text;
 
@@ -231,7 +232,15 @@ e_html_editor_view_force_spell_check_for_current_paragraph (EHTMLEditorView *vie
                return;
 
        selection = e_html_editor_view_get_selection (view);
-       caret = e_html_editor_selection_save_caret_position (selection);
+       e_html_editor_selection_save (selection);
+
+       selection_start_marker = webkit_dom_document_query_selector (
+               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 (!selection_start_marker || !selection_end_marker)
+               return;
 
        /* Block callbacks of selection-changed signal as we don't want to
         * recount all the block format things in EHTMLEditorSelection and here as well
@@ -240,11 +249,15 @@ e_html_editor_view_force_spell_check_for_current_paragraph (EHTMLEditorView *vie
                view, html_editor_view_selection_changed_cb, NULL);
        e_html_editor_selection_block_selection_changed (selection);
 
-       parent = webkit_dom_node_get_parent_element (WEBKIT_DOM_NODE (caret));
-       element = caret;
+       parent = webkit_dom_node_get_parent_element (
+               WEBKIT_DOM_NODE (selection_start_marker));
 
-       while (parent && !WEBKIT_DOM_IS_HTML_BODY_ELEMENT (parent)) {
-               element = parent;
+       while (parent &&
+              !WEBKIT_DOM_IS_HTML_DIV_ELEMENT (parent) &&
+              !WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (parent) &&
+              !WEBKIT_DOM_IS_HTMLU_LIST_ELEMENT (parent) &&
+              !WEBKIT_DOM_IS_HTMLO_LIST_ELEMENT (parent) &&
+              !WEBKIT_DOM_IS_HTML_PRE_ELEMENT (parent)) {
                parent = webkit_dom_node_get_parent_element (
                        WEBKIT_DOM_NODE (parent));
        }
@@ -252,7 +265,10 @@ e_html_editor_view_force_spell_check_for_current_paragraph (EHTMLEditorView *vie
        /* Append some text on the end of the element */
        text = webkit_dom_document_create_text_node (document, "-x-evo-end");
        webkit_dom_node_append_child (
-               WEBKIT_DOM_NODE (element), WEBKIT_DOM_NODE (text), NULL);
+               webkit_dom_node_get_parent_node (
+                       WEBKIT_DOM_NODE (selection_end_marker)),
+               WEBKIT_DOM_NODE (text),
+               NULL);
 
        /* Create range that's pointing on the end of this text */
        end_range = webkit_dom_document_create_range (document);
@@ -263,7 +279,7 @@ e_html_editor_view_force_spell_check_for_current_paragraph (EHTMLEditorView *vie
        /* Move on the beginning of the paragraph */
        actual = webkit_dom_document_create_range (document);
        webkit_dom_range_select_node_contents (
-               actual, WEBKIT_DOM_NODE (element), NULL);
+               actual, WEBKIT_DOM_NODE (parent), NULL);
        webkit_dom_range_collapse (actual, TRUE, NULL);
        webkit_dom_dom_selection_remove_all_ranges (dom_selection);
        webkit_dom_dom_selection_add_range (dom_selection, actual);
@@ -288,7 +304,7 @@ e_html_editor_view_force_spell_check_for_current_paragraph (EHTMLEditorView *vie
                view, html_editor_view_selection_changed_cb, NULL);
        e_html_editor_selection_unblock_selection_changed (selection);
 
-       e_html_editor_selection_restore_caret_position (selection);
+       e_html_editor_selection_restore (selection);
 }
 
 static void
@@ -720,10 +736,12 @@ body_input_event_cb (WebKitDOMElement *element,
                                                WEBKIT_DOM_NODE (marker),
                                                NULL);
                                }
+                               e_html_editor_selection_restore (selection);
+                               e_html_editor_view_force_spell_check_for_current_paragraph (view);
+                               return;
                        }
                }
                e_html_editor_selection_restore (selection);
-               e_html_editor_view_force_spell_check (view);
        }
 }
 
@@ -2107,7 +2125,7 @@ change_quoted_block_to_normal (EHTMLEditorView *view)
                        remove_node_if_empty (
                                webkit_dom_node_get_next_sibling (
                                        WEBKIT_DOM_NODE (paragraph)));
-                       e_html_editor_view_force_spell_check (view);
+                       e_html_editor_view_force_spell_check_for_current_paragraph (view);
                }
        }
 


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