[evolution/webkit-composer: 208/210] Bug #702444 - [webkit-composer] Text paste doesn't wrap lines



commit 9e74954026fea329a05b2f508c569f3cfc4f619b
Author: Tomas Popela <tpopela redhat com>
Date:   Tue Jul 2 11:41:07 2013 +0200

    Bug #702444 - [webkit-composer] Text paste doesn't wrap lines

 composer/e-composer-private.c |    2 +-
 e-util/e-editor-selection.c   |   41 ++++++++++++++++++++---------------------
 2 files changed, 21 insertions(+), 22 deletions(-)
---
diff --git a/composer/e-composer-private.c b/composer/e-composer-private.c
index 07b986b..c9c1f31 100644
--- a/composer/e-composer-private.c
+++ b/composer/e-composer-private.c
@@ -610,7 +610,7 @@ e_composer_paste_text (EMsgComposer *composer,
 
        if (e_editor_selection_get_block_format (editor_selection) ==
                        E_EDITOR_SELECTION_BLOCK_FORMAT_PARAGRAPH) {
-               e_editor_selection_wrap_lines (editor_selection, TRUE, NULL);
+               e_editor_selection_wrap_lines (editor_selection, FALSE, NULL);
        }
 
        g_free (text);
diff --git a/e-util/e-editor-selection.c b/e-util/e-editor-selection.c
index c68f013..56f070b 100644
--- a/e-util/e-editor-selection.c
+++ b/e-util/e-editor-selection.c
@@ -3166,6 +3166,7 @@ e_editor_selection_wrap_lines (EEditorSelection *selection,
        } else {
                /* When there is nothing selected, we select and wrap everything
                 * that is not containing signature */
+               e_editor_selection_save_caret_position (selection);
                if (g_strcmp0 (e_editor_selection_get_string (selection), "") == 0) {
                        WebKitDOMNodeList *list;
                        WebKitDOMNode *signature = NULL;
@@ -3178,30 +3179,25 @@ e_editor_selection_wrap_lines (EEditorSelection *selection,
                        if (webkit_dom_node_list_get_length (list) > 0)
                                signature = webkit_dom_node_list_item (list, 0);
 
-                       if (signature) {
-                               list = webkit_dom_document_query_selector_all (document, "div, pre, p", NULL);
-
-                               for (ii = 0; ii < webkit_dom_node_list_get_length (list); ii++) {
-                                       WebKitDOMNode *node;
-                                       node = webkit_dom_node_list_item (list, ii);
+                       list = webkit_dom_document_query_selector_all (document, "div.-x-evo-paragraph, 
p.-x-evo-paragraph", NULL);
+                       for (ii = 0; ii < webkit_dom_node_list_get_length (list); ii++) {
+                               WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
 
-                                       /* Select elements that actualy have some text content */
-                                       if (g_utf8_strlen (webkit_dom_node_get_text_content (node), -1) == 0)
-                                               continue;
+                               /* Select elements that actualy have some text content */
+                               if (g_utf8_strlen (webkit_dom_node_get_text_content (node), -1) == 0)
+                                       continue;
 
-                                       if (!webkit_dom_node_contains (node, signature)
-                                               && !webkit_dom_node_contains (signature, node)) {
+                               if (signature) {
+                                       if (!webkit_dom_node_contains (node, signature) &&
+                                           !webkit_dom_node_contains (signature, node)) {
 
                                                wrap_lines (NULL, node, web_view, jump_to_previous_line,
                                                            FALSE, selection->priv->word_wrap_length, 
delete_pressed);
                                        }
+                               } else {
+                                       wrap_lines (NULL, node, web_view, jump_to_previous_line,
+                                                   FALSE, selection->priv->word_wrap_length, delete_pressed);
                                }
-                       } else {
-                               /* Wrap all */
-                               WebKitDOMNode *body;
-                               body = WEBKIT_DOM_NODE (webkit_dom_document_get_body (document));
-                               wrap_lines (NULL, body, web_view, jump_to_previous_line,
-                                           FALSE, selection->priv->word_wrap_length, delete_pressed);
                        }
                } else {
                        /* If we have selection -> wrap it */
@@ -3210,19 +3206,22 @@ e_editor_selection_wrap_lines (EEditorSelection *selection,
                }
        }
 
+       active_paragraph = webkit_dom_document_get_element_by_id (document, "-x-evo-active-paragraph");
        /* We have to move caret on position where it was before modifying the text */
        if (return_pressed) {
-               active_paragraph = webkit_dom_document_get_element_by_id (document, 
"-x-evo-active-paragraph");
                e_editor_selection_clear_caret_position_marker (selection);
                move_caret_into_element (document, active_paragraph);
                webkit_dom_dom_selection_modify (window_selection, "move", "forward", "character");
        } else {
-               e_editor_selection_restore_caret_position (selection);
+               if (while_typing)
+                       e_editor_selection_restore_caret_position (selection);
+               else
+                       e_editor_selection_clear_caret_position_marker (selection);
        }
 
        /* Set paragraph as non-active */
-       active_paragraph = webkit_dom_document_get_element_by_id (document, "-x-evo-active-paragraph");
-       webkit_dom_element_remove_attribute (WEBKIT_DOM_ELEMENT (active_paragraph), "id");
+       if (active_paragraph)
+               webkit_dom_element_remove_attribute (WEBKIT_DOM_ELEMENT (active_paragraph), "id");
 
        g_object_unref (editor_widget);
 }


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