[evolution/wip/webkit-composer] Bug 726634 - [webkit-composer] Turning on list-style paragraph style deletes text



commit 79fb94022b2f484c7bcf88cfa6cf3ef620a6c946
Author: Tomas Popela <tpopela redhat com>
Date:   Wed Mar 19 11:17:32 2014 +0100

    Bug 726634 - [webkit-composer] Turning on list-style paragraph style deletes text
    
    We have to copy items from previous block to newly inserted list.

 e-util/e-editor-selection.c |   33 ++++++++++++++++++++++++---------
 1 files changed, 24 insertions(+), 9 deletions(-)
---
diff --git a/e-util/e-editor-selection.c b/e-util/e-editor-selection.c
index be2e075..9d1fe46 100644
--- a/e-util/e-editor-selection.c
+++ b/e-util/e-editor-selection.c
@@ -1448,10 +1448,10 @@ insert_new_list (EEditorSelection *selection,
                  EEditorSelectionBlockFormat to,
                  gboolean html_mode)
 {
-       gboolean inserting_ordered_list = FALSE;
+       gboolean inserting_ordered_list = FALSE, empty;
        gchar *content;
        WebKitDOMRange *range;
-       WebKitDOMElement *element;
+       WebKitDOMElement *element, *li;
        WebKitDOMNode *node;
 
        range = editor_selection_get_current_range (selection);
@@ -1462,8 +1462,9 @@ insert_new_list (EEditorSelection *selection,
        if (to != E_EDITOR_SELECTION_BLOCK_FORMAT_UNORDERED_LIST)
                inserting_ordered_list = TRUE;
 
-       /* Sometimes there is UNICODE_ZERO_WIDTH_SPACE so we have to remove it */
-       webkit_dom_node_set_text_content (node, "", NULL);
+       content = webkit_dom_node_get_text_content (node);
+       empty = !*content || (g_strcmp0 (content, UNICODE_ZERO_WIDTH_SPACE) == 0);
+       g_free (content);
 
        /* Create list elements */
        element = webkit_dom_document_create_element (
@@ -1485,12 +1486,26 @@ insert_new_list (EEditorSelection *selection,
 
        /* We have to use again the hidden space to move caret into newly
         * inserted list */
-       content = g_strconcat ("<li>", UNICODE_ZERO_WIDTH_SPACE, "</li>", NULL);
-       webkit_dom_html_element_set_inner_html (
-               WEBKIT_DOM_HTML_ELEMENT (element),
-               content,
+       li = webkit_dom_document_create_element (document, "LI", NULL);
+       if (empty) {
+               webkit_dom_html_element_set_inner_html (
+                       WEBKIT_DOM_HTML_ELEMENT (li),
+                       UNICODE_ZERO_WIDTH_SPACE,
+                       NULL);
+       } else {
+               /* Copy elements from previous block to list */
+               while (webkit_dom_node_has_child_nodes (node)) {
+                       webkit_dom_node_append_child (
+                               WEBKIT_DOM_NODE (li),
+                               webkit_dom_node_get_first_child (node),
+                               NULL);
+               }
+       }
+
+       webkit_dom_node_append_child (
+               WEBKIT_DOM_NODE (element),
+               WEBKIT_DOM_NODE (li),
                NULL);
-       g_free (content);
 
        node = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (element));
        webkit_dom_node_append_child (


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