diff options
author | Tomas Popela <tpopela@redhat.com> | 2014-08-27 22:06:07 +0800 |
---|---|---|
committer | Tomas Popela <tpopela@redhat.com> | 2014-08-27 22:12:02 +0800 |
commit | 6a0592918ac4bf109d67b619cdf3835239b700d4 (patch) | |
tree | 29eac1651b3ee2923a7a95ab3888ab67a7b1d231 /e-util | |
parent | 94ac03022048a12b6a43c970ab6a95eef865e7b6 (diff) | |
download | gsoc2013-evolution-6a0592918ac4bf109d67b619cdf3835239b700d4.tar gsoc2013-evolution-6a0592918ac4bf109d67b619cdf3835239b700d4.tar.gz gsoc2013-evolution-6a0592918ac4bf109d67b619cdf3835239b700d4.tar.bz2 gsoc2013-evolution-6a0592918ac4bf109d67b619cdf3835239b700d4.tar.lz gsoc2013-evolution-6a0592918ac4bf109d67b619cdf3835239b700d4.tar.xz gsoc2013-evolution-6a0592918ac4bf109d67b619cdf3835239b700d4.tar.zst gsoc2013-evolution-6a0592918ac4bf109d67b619cdf3835239b700d4.zip |
Fix handling of the selection in the composer when saving the message draft
When saving the draft don't lose the active selection in the web view.
Also restore the selection when the draft is again opened. Also fix the
situations when the spell check was not activated when the composer was
opened.
Diffstat (limited to 'e-util')
-rw-r--r-- | e-util/e-html-editor-selection.c | 70 | ||||
-rw-r--r-- | e-util/e-html-editor-selection.h | 3 | ||||
-rw-r--r-- | e-util/e-html-editor-view.c | 20 |
3 files changed, 49 insertions, 44 deletions
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c index e691b6f4f9..84f6fbc41c 100644 --- a/e-util/e-html-editor-selection.c +++ b/e-util/e-html-editor-selection.c @@ -3552,28 +3552,6 @@ e_html_editor_selection_is_monospaced (EHTMLEditorSelection *selection) return ret_val; } -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); -} - /** * e_html_editor_selection_set_monospaced: * @selection: an #EHTMLEditorSelection @@ -3666,7 +3644,8 @@ e_html_editor_selection_set_monospaced (EHTMLEditorSelection *selection, webkit_dom_range_insert_node ( range, WEBKIT_DOM_NODE (monospace), NULL); - move_caret_into_element (document, monospace); + e_html_editor_selection_move_caret_into_element ( + document, monospace); } } else { gboolean is_bold, is_italic, is_underline, is_strikethrough; @@ -4750,6 +4729,28 @@ e_html_editor_selection_replace_image_src (EHTMLEditorSelection *selection, image_load_and_insert_async (selection, element, image_uri); } +void +e_html_editor_selection_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); +} + /** * e_html_editor_selection_clear_caret_position_marker: * @selection: an #EHTMLEditorSelection @@ -4940,14 +4941,14 @@ e_html_editor_selection_restore_caret_position (EHTMLEditorSelection *selection) if (element_has_class (WEBKIT_DOM_ELEMENT (next_sibling), "-x-evo-paragraph")) { remove_node (WEBKIT_DOM_NODE (element)); - move_caret_into_element ( + e_html_editor_selection_move_caret_into_element ( document, WEBKIT_DOM_ELEMENT (next_sibling)); goto out; } } - move_caret_into_element (document, element); + e_html_editor_selection_move_caret_into_element (document, element); if (fix_after_quoting) { prev_sibling = webkit_dom_node_get_previous_sibling ( @@ -6221,16 +6222,19 @@ e_html_editor_selection_scroll_to_caret (EHTMLEditorSelection *selection) EHTMLEditorView *view; WebKitDOMDocument *document; WebKitDOMDOMWindow *window; - WebKitDOMElement *caret; + WebKitDOMElement *selection_start_marker; - caret = e_html_editor_selection_save_caret_position (selection); - if (!caret) - return; + e_html_editor_selection_save (selection); view = e_html_editor_selection_ref_html_editor_view (selection); document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view)); g_object_unref (view); + selection_start_marker = webkit_dom_document_get_element_by_id ( + document, "-x-evo-selection-start-marker"); + if (!selection_start_marker) + return; + window = webkit_dom_document_get_default_view (document); window_top = webkit_dom_dom_window_get_scroll_y (window); @@ -6238,14 +6242,14 @@ e_html_editor_selection_scroll_to_caret (EHTMLEditorSelection *selection) window_bottom = window_top + webkit_dom_dom_window_get_inner_height (window); window_right = window_left + webkit_dom_dom_window_get_inner_width (window); - element_left = webkit_dom_element_get_offset_left (caret); - element_top = webkit_dom_element_get_offset_top (caret); + element_left = webkit_dom_element_get_offset_left (selection_start_marker); + element_top = webkit_dom_element_get_offset_top (selection_start_marker); /* Check if caret is inside viewport, if not move to it */ if (!(element_top >= window_top && element_top <= window_bottom && element_left >= window_left && element_left <= window_right)) { - webkit_dom_element_scroll_into_view (caret, TRUE); + webkit_dom_element_scroll_into_view (selection_start_marker, TRUE); } - e_html_editor_selection_clear_caret_position_marker (selection); + e_html_editor_selection_restore (selection); } diff --git a/e-util/e-html-editor-selection.h b/e-util/e-html-editor-selection.h index 2bef77f052..3290dfe39b 100644 --- a/e-util/e-html-editor-selection.h +++ b/e-util/e-html-editor-selection.h @@ -183,6 +183,9 @@ void e_html_editor_selection_replace_image_src void e_html_editor_selection_insert_image (EHTMLEditorSelection *selection, const gchar *image_uri); +void e_html_editor_selection_move_caret_into_element + (WebKitDOMDocument *document, + WebKitDOMElement *element); void e_html_editor_selection_clear_caret_position_marker (EHTMLEditorSelection *selection); WebKitDOMNode * diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c index 90a75de3ff..e0028ffa15 100644 --- a/e-util/e-html-editor-view.c +++ b/e-util/e-html-editor-view.c @@ -1202,6 +1202,14 @@ html_editor_view_load_status_changed (EHTMLEditorView *view) move_elements_to_body (document); repair_gmail_blockquotes (document); + if (webkit_dom_element_get_attribute (WEBKIT_DOM_ELEMENT (body), "data-evo-draft")) { + /* Restore the selection how it was when the draft was saved */ + e_html_editor_selection_move_caret_into_element ( + document, WEBKIT_DOM_ELEMENT (body)); + e_html_editor_selection_restore ( + e_html_editor_view_get_selection (view)); + } + /* Register on input event that is called when the content (body) is modified */ register_input_event_listener_on_body (view); @@ -6185,17 +6193,11 @@ process_content_for_saving_as_draft (EHTMLEditorView *view) { WebKitDOMDocument *document; WebKitDOMHTMLElement *body; - WebKitDOMElement *element, *document_element; + WebKitDOMElement *document_element; gchar *content; document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view)); body = webkit_dom_document_get_body (document); - element = webkit_dom_document_get_element_by_id ( - document, "-x-evo-caret-position"); - - if (element) - webkit_dom_element_set_attribute ( - element, "style", "display: none; color: red;", NULL); webkit_dom_element_set_attribute ( WEBKIT_DOM_ELEMENT (body), "data-evo-draft", "", NULL); @@ -6207,10 +6209,6 @@ process_content_for_saving_as_draft (EHTMLEditorView *view) webkit_dom_element_remove_attribute ( WEBKIT_DOM_ELEMENT (body), "data-evo-draft"); - if (element) - webkit_dom_element_set_attribute ( - element, "style", "color: red;", NULL); - return content; } |