[evolution] EHTMLEditorView - Save selection instead of just caret position when forcing the spell check
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] EHTMLEditorView - Save selection instead of just caret position when forcing the spell check
- Date: Tue, 15 Jul 2014 09:10:27 +0000 (UTC)
commit de832c906f73be6ec77f7bfec2e648fee22fe737
Author: Tomas Popela <tpopela redhat com>
Date: Tue Jul 15 10:42:00 2014 +0200
EHTMLEditorView - Save selection instead of just caret position when forcing the spell check
e-util/e-html-editor-selection.c | 16 ++-------
e-util/e-html-editor-view.c | 68 +++++++++++++++++++------------------
2 files changed, 39 insertions(+), 45 deletions(-)
---
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c
index 4cfe976..01141c7 100644
--- a/e-util/e-html-editor-selection.c
+++ b/e-util/e-html-editor-selection.c
@@ -1983,8 +1983,8 @@ format_change_block_to_list (EHTMLEditorSelection *selection,
merge_lists_if_possible (WEBKIT_DOM_NODE (list));
- e_html_editor_view_force_spell_check (view);
e_html_editor_selection_restore (selection);
+ e_html_editor_view_force_spell_check (view);
}
static void
@@ -2163,7 +2163,6 @@ e_html_editor_selection_set_block_format (EHTMLEditorSelection *selection,
EHTMLEditorView *view;
EHTMLEditorSelectionBlockFormat current_format;
const gchar *value;
- gboolean has_selection = FALSE;
gboolean from_list = FALSE, to_list = FALSE, html_mode;
WebKitDOMDocument *document;
WebKitDOMRange *range;
@@ -2222,9 +2221,6 @@ e_html_editor_selection_set_block_format (EHTMLEditorSelection *selection,
break;
}
- if (g_strcmp0 (e_html_editor_selection_get_string (selection), "") != 0)
- has_selection = TRUE;
-
/* H1 - H6 have bold font by default */
if (format >= E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_H1 &&
format <= E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_H6)
@@ -2257,8 +2253,7 @@ e_html_editor_selection_set_block_format (EHTMLEditorSelection *selection,
if (!from_list && to_list)
format_change_block_to_list (selection, format, view, document);
- if (!has_selection)
- e_html_editor_view_force_spell_check (view);
+ e_html_editor_view_force_spell_check (view);
g_object_unref (view);
@@ -2821,11 +2816,9 @@ e_html_editor_selection_indent (EHTMLEditorSelection *selection)
block = next_block;
}
-
out:
- e_html_editor_view_force_spell_check (view);
-
e_html_editor_selection_restore (selection);
+ e_html_editor_view_force_spell_check (view);
g_object_unref (view);
@@ -3100,9 +3093,8 @@ e_html_editor_selection_unindent (EHTMLEditorSelection *selection)
block = next_block;
}
out:
- e_html_editor_view_force_spell_check (view);
-
e_html_editor_selection_restore (selection);
+ e_html_editor_view_force_spell_check (view);
g_object_unref (view);
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index 03d9cb7..0270cbc 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -292,28 +292,6 @@ e_html_editor_view_force_spell_check_for_current_paragraph (EHTMLEditorView *vie
}
static void
-move_caret_into_element (WebKitDOMDocument *document,
- WebKitDOMElement *element)
-{
- WebKitDOMDOMWindow *window;
- WebKitDOMDOMSelection *window_selection;
- WebKitDOMRange *new_range;
-
- if (!element)
- return;
-
- window = webkit_dom_document_get_default_view (document);
- window_selection = webkit_dom_dom_window_get_selection (window);
- new_range = webkit_dom_document_create_range (document);
-
- webkit_dom_range_select_node_contents (
- new_range, WEBKIT_DOM_NODE (element), NULL);
- webkit_dom_range_collapse (new_range, FALSE, NULL);
- webkit_dom_dom_selection_remove_all_ranges (window_selection);
- webkit_dom_dom_selection_add_range (window_selection, new_range);
-}
-
-static void
refresh_spell_check (EHTMLEditorView *view,
gboolean enable_spell_check)
{
@@ -321,6 +299,7 @@ refresh_spell_check (EHTMLEditorView *view,
WebKitDOMDocument *document;
WebKitDOMDOMSelection *dom_selection;
WebKitDOMDOMWindow *window;
+ WebKitDOMElement *selection_start_marker, *selection_end_marker;
WebKitDOMHTMLElement *body;
WebKitDOMRange *end_range, *actual;
WebKitDOMText *text;
@@ -338,15 +317,38 @@ refresh_spell_check (EHTMLEditorView *view,
NULL);
selection = e_html_editor_view_get_selection (view);
- e_html_editor_selection_save_caret_position (selection);
+ e_html_editor_selection_save (selection);
- /* Sometimes the web view is not event focused, so we have to move caret
- * into body */
- if (!webkit_dom_document_get_element_by_id (document, "-x-evo-caret-position")) {
- move_caret_into_element (
- document,
- WEBKIT_DOM_ELEMENT (webkit_dom_document_get_body (document)));
- e_html_editor_selection_save_caret_position (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);
+
+ /* Sometimes the web view is not focused, so we have to save the selection
+ * manually into the body */
+ if (!selection_start_marker || !selection_end_marker) {
+ 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 callbacks of selection-changed signal as we don't want to
@@ -391,7 +393,7 @@ refresh_spell_check (EHTMLEditorView *view,
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);
}
void
@@ -719,9 +721,9 @@ body_input_event_cb (WebKitDOMElement *element,
NULL);
}
}
- e_html_editor_view_force_spell_check (view);
}
e_html_editor_selection_restore (selection);
+ e_html_editor_view_force_spell_check (view);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]