[evolution/wip/webkit-composer: 867/966] EEditorWidget: Remove zero width space safely to avoid caret restoration at wrong position



commit a5f162bb02795444262b3e8ae56367eba8e5aaae
Author: Tomas Popela <tpopela redhat com>
Date:   Wed Mar 5 13:51:35 2014 +0100

    EEditorWidget: Remove zero width space safely to avoid caret restoration at wrong position
    
    When removing zero width space character from the beginning of word use
    webkit_dom_character_data_replace_data instead of modifying node's text
    content.

 e-util/e-editor-widget.c |   14 ++++----------
 1 files changed, 4 insertions(+), 10 deletions(-)
---
diff --git a/e-util/e-editor-widget.c b/e-util/e-editor-widget.c
index fab54ea..9600f8f 100644
--- a/e-util/e-editor-widget.c
+++ b/e-util/e-editor-widget.c
@@ -317,19 +317,13 @@ body_input_event_cb (WebKitDOMElement *element,
        /* If text before caret includes UNICODE_ZERO_WIDTH_SPACE character, remove it */
        node = webkit_dom_range_get_end_container (range, NULL);
        if (WEBKIT_DOM_IS_TEXT (node)) {
-               gchar *text = webkit_dom_node_get_text_content (node);
+               gchar *text = webkit_dom_character_data_get_data (WEBKIT_DOM_CHARACTER_DATA (node));
                glong length = g_utf8_strlen (text, -1);
                /* We have to preserve empty paragraphs with just UNICODE_ZERO_WIDTH_SPACE
                 * character as when we will remove it it will collapse */
-               if (length > 1 && strstr (text, UNICODE_ZERO_WIDTH_SPACE)) {
-                       WebKitDOMDocument *document;
-                       WebKitDOMDOMWindow *window;
-                       WebKitDOMDOMSelection *selection;
-                       GString *res = e_str_replace_string (text, UNICODE_ZERO_WIDTH_SPACE, "");
-
-                       webkit_dom_node_set_text_content (node, res->str, NULL);
-
-                       g_string_free (res, TRUE);
+               if (length > 1 && g_str_has_prefix (text, UNICODE_ZERO_WIDTH_SPACE)) {
+                       webkit_dom_character_data_replace_data (
+                               WEBKIT_DOM_CHARACTER_DATA (node), 0, 1, "", NULL);
                }
                g_free (text);
 


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