[evolution/wip/webkit2] EHTMLEditorView - Modifying the text of a smiley should convert the smiley to a text node



commit f04f1beb5c620461eed4b2d58a0f7085fea96082
Author: Tomas Popela <tpopela redhat com>
Date:   Tue Mar 1 13:39:58 2016 +0100

    EHTMLEditorView - Modifying the text of a smiley should convert the smiley to a text node

 .../composer/e-html-editor-view-dom-functions.c    |  106 +++++++++++++-------
 1 files changed, 71 insertions(+), 35 deletions(-)
---
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 eeec279..2e28ac9 100644
--- a/web-extensions/composer/e-html-editor-view-dom-functions.c
+++ b/web-extensions/composer/e-html-editor-view-dom-functions.c
@@ -8362,6 +8362,68 @@ return_pressed_in_empty_list_item (WebKitDOMDocument *document,
        return FALSE;
 }
 
+static void
+change_smiley_to_plain_text (WebKitDOMDocument *document)
+{
+       WebKitDOMElement *element;
+       WebKitDOMNode *parent;
+       gboolean in_smiley = FALSE;
+
+       dom_selection_save (document);
+       element = webkit_dom_document_get_element_by_id (
+               document, "-x-evo-selection-start-marker");
+
+       parent = webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (element));
+       if (WEBKIT_DOM_IS_ELEMENT (parent) &&
+           element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-smiley-text"))
+               in_smiley = TRUE;
+       else {
+               if (dom_selection_is_collapsed (document)) {
+                       WebKitDOMNode *prev_sibling;
+
+                       prev_sibling = webkit_dom_node_get_previous_sibling (WEBKIT_DOM_NODE (element));
+                       if (prev_sibling && WEBKIT_DOM_IS_TEXT (prev_sibling)) {
+                               gchar *text = webkit_dom_character_data_get_data (
+                                       WEBKIT_DOM_CHARACTER_DATA (prev_sibling));
+
+                               if (g_strcmp0 (text, UNICODE_ZERO_WIDTH_SPACE) == 0) {
+                                       remove_node (prev_sibling);
+                                       in_smiley = TRUE;
+                                       prev_sibling = webkit_dom_node_get_previous_sibling (WEBKIT_DOM_NODE 
(element));
+                                       if (WEBKIT_DOM_IS_ELEMENT (prev_sibling) &&
+                                           element_has_class (WEBKIT_DOM_ELEMENT (prev_sibling), 
"-x-evo-smiley-wrapper"))
+                                               parent = webkit_dom_node_get_last_child (prev_sibling);
+                               }
+
+                               g_free (text);
+                       }
+               } else {
+                       element = webkit_dom_document_get_element_by_id (
+                               document, "-x-evo-selection-end-marker");
+
+                       parent = webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (element));
+                       if (WEBKIT_DOM_IS_ELEMENT (parent) &&
+                           element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-smiley-text"))
+                               in_smiley = TRUE;
+               }
+       }
+
+       if (in_smiley) {
+               WebKitDOMNode *wrapper, *child;
+
+               wrapper = webkit_dom_node_get_parent_node (parent);
+               while ((child = webkit_dom_node_get_first_child (parent)))
+                       webkit_dom_node_insert_before (
+                               webkit_dom_node_get_parent_node (wrapper),
+                               child,
+                               wrapper,
+                               NULL);
+               remove_node (wrapper);
+       }
+
+       dom_selection_restore (document);
+}
+
 gboolean
 dom_process_on_key_press (WebKitDOMDocument *document,
                           EHTMLEditorWebExtension *extension,
@@ -8384,7 +8446,7 @@ dom_process_on_key_press (WebKitDOMDocument *document,
                gboolean first_cell = FALSE;
                WebKitDOMNode *table = NULL;
 
-               /* Return pressed in the the begining of the first cell will insert
+               /* Return pressed in the beginning of the first cell will insert
                 * new block before the table (and move the caret there) if none
                 * is already there, otherwise it will act as normal return. */
                if (selection_is_in_table (document, &first_cell, &table) && first_cell) {
@@ -8478,40 +8540,14 @@ dom_process_on_key_press (WebKitDOMDocument *document,
 
                html_mode = e_html_editor_web_extension_get_html_mode (extension);
                if (!html_mode && e_html_editor_web_extension_get_magic_links_enabled (extension)) {
-                       WebKitDOMElement *element, *parent;
-                       gboolean in_smiley = FALSE;
-
-                       dom_selection_save (document);
-                       element = webkit_dom_document_get_element_by_id (
-                               document, "-x-evo-selection-start-marker");
-
-                       parent = webkit_dom_node_get_parent_element (WEBKIT_DOM_NODE (element));
-                       if (element_has_class (parent, "-x-evo-smiley-text"))
-                               in_smiley = TRUE;
-                       else {
-                               if (!dom_selection_is_collapsed (document)) {
-                                       element = webkit_dom_document_get_element_by_id (
-                                               document, "-x-evo-selection-end-marker");
-
-                                       parent = webkit_dom_node_get_parent_element (WEBKIT_DOM_NODE 
(element));
-                                       if (element_has_class (parent, "-x-evo-smiley-text"))
-                                               in_smiley = TRUE;
-                               }
-                       }
-
-                       if (in_smiley) {
-                               WebKitDOMNode *wrapper, *child;
-
-                               wrapper = webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (parent));
-                               while ((child = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (parent))))
-                                       webkit_dom_node_insert_before (
-                                               webkit_dom_node_get_parent_node (wrapper),
-                                               child,
-                                               wrapper,
-                                               NULL);
-                               remove_node (wrapper);
-                       }
-                       dom_selection_restore (document);
+                       /* If deleting something in a smiley it won't be a smiley
+                        * anymore (at least from Evolution' POV), so remove all
+                        * the elements that are hidden in the wrapper and leave
+                        * just the text. Also this ensures that when a smiley is
+                        * recognized and we press the BackSpace key we won't delete
+                        * the UNICODE_HIDDEN_SPACE, but we will correctly delete
+                        * the last character of smiley. */
+                       change_smiley_to_plain_text (document);
                }
                if (key_val == GDK_KEY_BackSpace && !html_mode) {
                        if (dom_delete_character_from_quoted_line_start (document, extension, key_val, 
state)) {


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