[evolution] Bug 751225 - Spell check selection changes font settings to initial settings
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Bug 751225 - Spell check selection changes font settings to initial settings
- Date: Thu, 16 Jul 2015 12:34:20 +0000 (UTC)
commit 410c434c48657ea49ac05dffc9f5d8c6a7d282bc
Author: Tomas Popela <tpopela redhat com>
Date: Thu Jul 16 14:26:30 2015 +0200
Bug 751225 - Spell check selection changes font settings to initial settings
Do the replace ourselves as the PasteAndmatchStyle function operates on clipboard's
content and doesn't accept the replacement that we pass to it.
e-util/e-html-editor-selection.c | 38 +++++++++++++++++++++++++++++++++-----
1 files changed, 33 insertions(+), 5 deletions(-)
---
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c
index d410518..61d1079 100644
--- a/e-util/e-html-editor-selection.c
+++ b/e-util/e-html-editor-selection.c
@@ -996,8 +996,10 @@ e_html_editor_selection_replace_caret_word (EHTMLEditorSelection *selection,
EHTMLEditorView *view;
WebKitWebView *web_view;
WebKitDOMDocument *document;
+ WebKitDOMDocumentFragment *fragment;
WebKitDOMDOMWindow *dom_window;
WebKitDOMDOMSelection *dom_selection;
+ WebKitDOMNode *node;
WebKitDOMRange *range;
g_return_if_fail (E_IS_HTML_EDITOR_SELECTION (selection));
@@ -1015,14 +1017,40 @@ e_html_editor_selection_replace_caret_word (EHTMLEditorSelection *selection,
webkit_dom_range_expand (range, "word", NULL);
webkit_dom_dom_selection_add_range (dom_selection, range);
- g_object_unref (range);
- g_object_unref (dom_selection);
- g_object_unref (dom_window);
- e_html_editor_view_exec_command (
- view, E_HTML_EDITOR_VIEW_COMMAND_PASTE_AND_MATCH_STYLE, replacement);
+ fragment = webkit_dom_range_extract_contents (range, NULL);
+
+ /* Get the text node to replace and leave other formatting nodes
+ * untouched (font color, boldness, ...). */
+ webkit_dom_node_normalize (WEBKIT_DOM_NODE (fragment));
+ node = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (fragment));
+ if (!WEBKIT_DOM_IS_TEXT (node)) {
+ while (node && WEBKIT_DOM_IS_ELEMENT (node))
+ node = webkit_dom_node_get_first_child (node);
+ }
+
+ if (node && WEBKIT_DOM_IS_TEXT (node)) {
+ WebKitDOMText *text;
+
+ /* Replace the word */
+ text = webkit_dom_document_create_text_node (document, replacement);
+ webkit_dom_node_replace_child (
+ webkit_dom_node_get_parent_node (node),
+ WEBKIT_DOM_NODE (text),
+ node,
+ NULL);
+
+ /* Insert the word on current location. */
+ webkit_dom_range_insert_node (range, WEBKIT_DOM_NODE (fragment), NULL);
+
+ webkit_dom_dom_selection_collapse_to_end (dom_selection, NULL);
+ }
+
e_html_editor_view_force_spell_check_for_current_paragraph (view);
+ g_object_unref (range);
+ g_object_unref (dom_selection);
+ g_object_unref (dom_window);
g_object_unref (view);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]