[evolution/wip/webkit2] EHTMLEditorView - Fix a link detection when ending a link with the Return key
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit2] EHTMLEditorView - Fix a link detection when ending a link with the Return key
- Date: Wed, 2 Mar 2016 16:58:28 +0000 (UTC)
commit 9b48342a99d6ec0b3b44b809298b9684432914a3
Author: Tomas Popela <tpopela redhat com>
Date: Wed Mar 2 16:30:34 2016 +0100
EHTMLEditorView - Fix a link detection when ending a link with the Return key
.../composer/e-html-editor-undo-redo-manager.c | 22 +++++++--
.../composer/e-html-editor-view-dom-functions.c | 50 ++++++++++++++------
2 files changed, 52 insertions(+), 20 deletions(-)
---
diff --git a/web-extensions/composer/e-html-editor-undo-redo-manager.c
b/web-extensions/composer/e-html-editor-undo-redo-manager.c
index dd8dc88..7e9d219 100644
--- a/web-extensions/composer/e-html-editor-undo-redo-manager.c
+++ b/web-extensions/composer/e-html-editor-undo-redo-manager.c
@@ -505,8 +505,6 @@ undo_delete (WebKitDOMDocument *document,
g_object_get_data (G_OBJECT (event->data.fragment), "-x-evo-return-key"))) {
if (key_press_event_process_return_key (document, extension)) {
body_key_up_event_process_return_key (document, extension);
- dom_force_spell_check_in_viewport (document, extension);
- return;
} else {
WebKitDOMElement *element;
WebKitDOMNode *next_sibling;
@@ -537,9 +535,14 @@ undo_delete (WebKitDOMDocument *document,
NULL);
}
dom_selection_restore (document);
-
- return;
}
+
+ e_html_editor_web_extension_set_return_key_pressed (extension, TRUE);
+ dom_check_magic_links (document, extension, FALSE);
+ e_html_editor_web_extension_set_return_key_pressed (extension, FALSE);
+ dom_force_spell_check_in_viewport (document, extension);
+
+ return;
}
if (!single_block) {
@@ -1860,6 +1863,12 @@ undo_input (EHTMLEditorUndoRedoManager *manager,
if (remove_anchor) {
WebKitDOMNode *child;
+ /* Don't ask me why, but I got into the situation where the node
+ * that I received above was out of the document, and all the
+ * modifications to it were of course not propagated to it. Let's
+ * get that node again. */
+ node = webkit_dom_dom_selection_get_anchor_node (dom_selection);
+ node = webkit_dom_node_get_parent_node (node);
while ((child = webkit_dom_node_get_first_child (node)))
webkit_dom_node_insert_before (
webkit_dom_node_get_parent_node (node), child, node, NULL);
@@ -2526,8 +2535,11 @@ e_html_editor_undo_redo_manager_redo (EHTMLEditorUndoRedoManager *manager)
WEBKIT_DOM_NODE (event->data.fragment));
text_content = webkit_dom_node_get_text_content (first_child);
/* Call magic links when the space was pressed. */
- if (g_str_has_prefix (text_content, UNICODE_NBSP))
+ if (g_str_has_prefix (text_content, UNICODE_NBSP)) {
+ e_html_editor_web_extension_set_space_key_pressed (extension, TRUE);
dom_check_magic_links (document, extension, FALSE);
+ e_html_editor_web_extension_set_space_key_pressed (extension, FALSE);
+ }
g_free (text_content);
}
break;
diff --git a/web-extensions/composer/e-html-editor-view-dom-functions.c
b/web-extensions/composer/e-html-editor-view-dom-functions.c
index 6f2ff72..5dbdc24 100644
--- a/web-extensions/composer/e-html-editor-view-dom-functions.c
+++ b/web-extensions/composer/e-html-editor-view-dom-functions.c
@@ -916,23 +916,41 @@ dom_check_magic_links (WebKitDOMDocument *document,
node = webkit_dom_range_get_end_container (range, NULL);
g_object_unref (range);
- if (return_key_pressed)
- node = webkit_dom_node_get_previous_sibling (node);
+ if (return_key_pressed) {
+ WebKitDOMNode* block;
+
+ node = webkit_dom_range_get_end_container (range, NULL);
+ block = get_parent_block_node_from_child (node);
+ /* Get previous block */
+ block = webkit_dom_node_get_previous_sibling (block);
+ /* If block is quoted content, get the last block there */
+ while (block && WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (block))
+ block = webkit_dom_node_get_last_child (block);
+
+ /* Get the last non-empty node */
+ node = webkit_dom_node_get_last_child (block);
+ if (WEBKIT_DOM_IS_CHARACTER_DATA (node) &&
+ webkit_dom_character_data_get_length (WEBKIT_DOM_CHARACTER_DATA (node)) == 0)
+ node = webkit_dom_node_get_previous_sibling (node);
+ } else {
+ dom_selection_save (document);
+ node = webkit_dom_range_get_end_container (range, NULL);
+ }
if (!node)
- return;
+ goto out;
if (!WEBKIT_DOM_IS_TEXT (node)) {
if (webkit_dom_node_has_child_nodes (node))
node = webkit_dom_node_get_first_child (node);
if (!WEBKIT_DOM_IS_TEXT (node))
- return;
+ goto out;
}
node_text = webkit_dom_text_get_whole_text (WEBKIT_DOM_TEXT (node));
if (!(node_text && *node_text) || !g_utf8_validate (node_text, -1, NULL)) {
g_free (node_text);
- return;
+ goto out;
}
if (strstr (node_text, "@") && !strstr (node_text, "://")) {
@@ -943,7 +961,7 @@ dom_check_magic_links (WebKitDOMDocument *document,
if (!regex) {
g_free (node_text);
- return;
+ goto out;
}
g_regex_match_all (regex, node_text, G_REGEX_MATCH_NOTEMPTY, &match_info);
@@ -953,12 +971,9 @@ dom_check_magic_links (WebKitDOMDocument *document,
const gchar *end_of_match = NULL;
gchar *final_url, *url_end_raw, *url_text;
glong url_start, url_end, url_length;
- WebKitDOMText *url_text_node;
+ WebKitDOMNode *url_text_node;
WebKitDOMElement *anchor;
- if (!return_key_pressed)
- dom_selection_save (document);
-
g_match_info_fetch_pos (match_info, 0, &start_pos_url, &end_pos_url);
/* Get start and end position of url in node's text because positions
@@ -986,7 +1001,7 @@ dom_check_magic_links (WebKitDOMDocument *document,
webkit_dom_text_split_text (
WEBKIT_DOM_TEXT (node), url_start, NULL);
- url_text_node = WEBKIT_DOM_TEXT (webkit_dom_node_get_next_sibling (node));
+ url_text_node = webkit_dom_node_get_next_sibling (node);
url_text = webkit_dom_character_data_get_data (
WEBKIT_DOM_CHARACTER_DATA (url_text_node));
@@ -1013,9 +1028,6 @@ dom_check_magic_links (WebKitDOMDocument *document,
WEBKIT_DOM_NODE (url_text_node),
NULL);
- if (!return_key_pressed)
- dom_selection_restore (document);
-
g_free (url_end_raw);
g_free (final_url);
g_free (url_text);
@@ -1060,7 +1072,7 @@ dom_check_magic_links (WebKitDOMDocument *document,
g_regex_unref (regex);
g_free (node_text);
g_free (text_to_append);
- return;
+ goto out;
}
/* edit only if href and description are the same */
@@ -1157,6 +1169,10 @@ dom_check_magic_links (WebKitDOMDocument *document,
g_match_info_free (match_info);
g_regex_unref (regex);
g_free (node_text);
+
+ out:
+ if (!return_key_pressed)
+ dom_selection_restore (document);
}
void
@@ -8907,7 +8923,11 @@ key_press_event_process_return_key (WebKitDOMDocument *document,
if (dom_selection_is_citation (document)) {
dom_remove_input_event_listener_from_body (document, extension);
if (split_citation (document, extension)) {
+ e_html_editor_web_extension_set_return_key_pressed (extension, TRUE);
+ dom_check_magic_links (document, extension, FALSE);
+ e_html_editor_web_extension_set_return_key_pressed (extension, FALSE);
e_html_editor_web_extension_set_content_changed (extension);
+
return TRUE;
}
return FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]