[evolution] Bug 742613 - New line added at the top of all replies



commit 48e4faa26c570b21e3e3a1fcc15b4756d6d09d35
Author: Tomas Popela <tpopela redhat com>
Date:   Fri Jan 9 13:33:59 2015 +0100

    Bug 742613 - New line added at the top of all replies
    
    Remove the unwanted block with initial caret position (above
    credentials) when the 'Start typing at the bottom on replying' is not
    selected. Leave it there just when the 'Keep signature above the
    original message on replying' option is set.

 composer/e-composer-private.c |   98 +++++++++++++++++++++++++---------------
 e-util/e-html-editor-view.c   |    9 +++-
 2 files changed, 67 insertions(+), 40 deletions(-)
---
diff --git a/composer/e-composer-private.c b/composer/e-composer-private.c
index f32707d..c18942f 100644
--- a/composer/e-composer-private.c
+++ b/composer/e-composer-private.c
@@ -826,6 +826,19 @@ prepare_paragraph (EHTMLEditorSelection *selection,
        return paragraph;
 }
 
+static WebKitDOMElement *
+prepare_top_signature_spacer (EHTMLEditorSelection *selection,
+                              WebKitDOMDocument *document)
+{
+       WebKitDOMElement *element;
+
+       element = prepare_paragraph (selection, document);
+       webkit_dom_element_remove_attribute (element, "id");
+       element_add_class (element, "-x-evo-top-signature-spacer");
+
+       return element;
+}
+
 static void
 composer_move_caret (EMsgComposer *composer)
 {
@@ -883,13 +896,8 @@ composer_move_caret (EMsgComposer *composer)
 
                if (e_html_editor_view_get_html_mode (view) &&
                    is_message_from_edit_as_new) {
-
-                       webkit_dom_range_select_node_contents (
-                               new_range, WEBKIT_DOM_NODE (body), NULL);
-                       webkit_dom_range_collapse (new_range, TRUE, NULL);
-
-                       webkit_dom_dom_selection_remove_all_ranges (dom_selection);
-                       webkit_dom_dom_selection_add_range (dom_selection, new_range);
+                       element = WEBKIT_DOM_ELEMENT (body);
+                       goto move_caret;
                } else
                        e_html_editor_selection_scroll_to_caret (editor_selection);
 
@@ -924,11 +932,12 @@ composer_move_caret (EMsgComposer *composer)
         *
         */
        if (signature && top_signature) {
-               element_add_class (signature, "-x-evo-top-signature");
-               element = prepare_paragraph (editor_selection, document);
+               WebKitDOMElement *spacer;
+
+               spacer = prepare_top_signature_spacer (editor_selection, document);
                webkit_dom_node_insert_before (
                        WEBKIT_DOM_NODE (body),
-                       WEBKIT_DOM_NODE (element),
+                       WEBKIT_DOM_NODE (spacer),
                        webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (signature)),
                        NULL);
        }
@@ -936,6 +945,22 @@ composer_move_caret (EMsgComposer *composer)
        if (webkit_dom_node_list_get_length (list) == 0)
                has_paragraphs_in_body = FALSE;
 
+       element = webkit_dom_document_get_element_by_id (document, "-x-evo-input-start");
+       if (!signature) {
+               if (start_bottom) {
+                       if (!element) {
+                               element = prepare_paragraph (editor_selection, document);
+                               webkit_dom_node_append_child (
+                                       WEBKIT_DOM_NODE (body),
+                                       WEBKIT_DOM_NODE (element),
+                                       NULL);
+                       }
+               } else
+                       element = WEBKIT_DOM_ELEMENT (body);
+
+               goto move_caret;
+       }
+
        if (!has_paragraphs_in_body) {
                element = prepare_paragraph (editor_selection, document);
                if (top_signature) {
@@ -948,26 +973,18 @@ composer_move_caret (EMsgComposer *composer)
                                webkit_dom_node_insert_before (
                                        WEBKIT_DOM_NODE (body),
                                        WEBKIT_DOM_NODE (element),
-                                       webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body)),
+                                       WEBKIT_DOM_NODE (signature),
                                        NULL);
                        }
                } else {
-                       if (start_bottom) {
+                       if (start_bottom)
                                webkit_dom_node_insert_before (
                                        WEBKIT_DOM_NODE (body),
                                        WEBKIT_DOM_NODE (element),
                                        WEBKIT_DOM_NODE (signature),
                                        NULL);
-                       } else {
-                               webkit_dom_node_insert_before (
-                                       WEBKIT_DOM_NODE (body),
-                                       WEBKIT_DOM_NODE (element),
-                                       webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body)),
-                                       NULL);
-                       }
                }
        } else {
-               element = webkit_dom_document_get_element_by_id (document, "-x-evo-input-start");
                if (!element && top_signature) {
                        element = prepare_paragraph (editor_selection, document);
                        if (start_bottom) {
@@ -982,23 +999,30 @@ composer_move_caret (EMsgComposer *composer)
                                        WEBKIT_DOM_NODE (signature),
                                        NULL);
                        }
+               } else if (element && top_signature && !start_bottom) {
+                       webkit_dom_node_insert_before (
+                               WEBKIT_DOM_NODE (body),
+                               WEBKIT_DOM_NODE (element),
+                               WEBKIT_DOM_NODE (signature),
+                               NULL);
                }
        }
 
-       webkit_dom_range_select_node_contents (
-               new_range, WEBKIT_DOM_NODE (element), NULL);
-       webkit_dom_range_collapse (new_range, TRUE, NULL);
+       g_object_unref (list);
+ move_caret:
+       if (element) {
+               webkit_dom_range_select_node_contents (
+                       new_range, WEBKIT_DOM_NODE (element), NULL);
+               webkit_dom_range_collapse (new_range, TRUE, NULL);
+               webkit_dom_dom_selection_remove_all_ranges (dom_selection);
+               webkit_dom_dom_selection_add_range (dom_selection, new_range);
+       }
 
        if (start_bottom)
                g_signal_connect (
                        view, "size-allocate",
                        G_CALLBACK (composer_size_allocate_cb), NULL);
 
-       webkit_dom_dom_selection_remove_all_ranges (dom_selection);
-       webkit_dom_dom_selection_add_range (dom_selection, new_range);
-
-       g_object_unref (list);
-
        e_html_editor_view_force_spell_check (view);
 
        e_html_editor_selection_unblock_selection_changed (editor_selection);
@@ -1143,8 +1167,14 @@ insert:
                if (id && (strlen (id) == 1) && (*id == '1')) {
                        /* If the top signature was set we have to remove the NL
                         * that was inserted after it */
-                       if (top_signature)
-                               remove_node (webkit_dom_node_get_next_sibling (wrapper));
+                       if (top_signature) {
+                               WebKitDOMElement *spacer;
+
+                               spacer = webkit_dom_document_query_selector (
+                                       document, ".-x-evo-top-signature-spacer", NULL);
+                               if (spacer)
+                                       remove_node_if_empty (WEBKIT_DOM_NODE (spacer));
+                       }
                        /* We have to remove the div containing the span with signature */
                        remove_node (wrapper);
 
@@ -1179,18 +1209,12 @@ insert:
                                                child,
                                                NULL);
                                } else {
-                                       WebKitDOMElement *input_start =
-                                               webkit_dom_document_get_element_by_id (
-                                                       document, "-x-evo-input-start");
                                        /* When we are using signature on top the caret
                                         * should be before the signature */
                                        webkit_dom_node_insert_before (
                                                WEBKIT_DOM_NODE (body),
                                                WEBKIT_DOM_NODE (element),
-                                               input_start ?
-                                                       webkit_dom_node_get_next_sibling (
-                                                               WEBKIT_DOM_NODE (input_start)) :
-                                                       child,
+                                               child,
                                                NULL);
                                }
                        } else {
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index 709ae82..dd4c34e 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -4663,6 +4663,8 @@ html_editor_convert_view_content (EHTMLEditorView *view,
                document, ".-x-evo-signature-content_wrapper", NULL);
        if (signature) {
                if (top_signature) {
+                       WebKitDOMElement *spacer;
+
                        webkit_dom_node_insert_before (
                                WEBKIT_DOM_NODE (wrapper),
                                WEBKIT_DOM_NODE (signature),
@@ -4672,10 +4674,11 @@ html_editor_convert_view_content (EHTMLEditorView *view,
                                                WEBKIT_DOM_NODE (paragraph)),
                                NULL);
                        /* Insert NL after the signature */
+                       spacer = prepare_paragraph (selection, document, FALSE);
+                       element_add_class (spacer, "-x-evo-top-signature-spacer");
                        webkit_dom_node_insert_before (
                                WEBKIT_DOM_NODE (wrapper),
-                               WEBKIT_DOM_NODE (prepare_paragraph (
-                                       selection, document, FALSE)),
+                               WEBKIT_DOM_NODE (spacer),
                                webkit_dom_node_get_next_sibling (
                                        WEBKIT_DOM_NODE (signature)),
                                NULL);
@@ -4809,7 +4812,7 @@ html_editor_convert_view_content (EHTMLEditorView *view,
                remove_node (WEBKIT_DOM_NODE (content_wrapper));
        }
 
-       if (view->priv->is_message_from_edit_as_new || view->priv->remove_initial_input_line) {
+       if (view->priv->is_message_from_edit_as_new || view->priv->remove_initial_input_line || 
!start_bottom) {
                WebKitDOMNode *child;
 
                remove_node (WEBKIT_DOM_NODE (paragraph));


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