[evolution] Don't preserve 'Preformatted' format if moving an empty block out of the quoted content



commit 6e54ed0abbd7b9b5be28a3c5d7004bbead7d8188
Author: Tomas Popela <tpopela redhat com>
Date:   Fri Mar 10 11:51:08 2017 +0100

    Don't preserve 'Preformatted' format if moving an empty block out of the quoted content
    
    If pressing the Backspace key to move a quoted block one level up (up to
    BODY) and block's format is 'Preformatted' then if the block is empty
    change the format of the block to 'Normal' if moved out of the quoted content.
    
    Unit test done by Milan Crha.

 src/e-util/test-html-editor-units-bugs.c           |   47 ++++++++++++++
 .../web-extension/e-editor-dom-functions.c         |   66 +++++++++++++++++++-
 2 files changed, 112 insertions(+), 1 deletions(-)
---
diff --git a/src/e-util/test-html-editor-units-bugs.c b/src/e-util/test-html-editor-units-bugs.c
index 1a92ca6..588827c 100644
--- a/src/e-util/test-html-editor-units-bugs.c
+++ b/src/e-util/test-html-editor-units-bugs.c
@@ -829,6 +829,52 @@ test_bug_775691 (TestFixture *fixture)
                g_test_fail ();
 }
 
+static void
+test_bug_779707 (TestFixture *fixture)
+{
+       test_utils_fixture_change_setting_boolean (fixture, "org.gnome.evolution.mail", 
"composer-reply-start-bottom", TRUE);
+       test_utils_fixture_change_setting_boolean (fixture, "org.gnome.evolution.mail", 
"composer-wrap-quoted-text-in-replies", FALSE);
+
+       if (!test_utils_process_commands (fixture,
+               "mode:plain\n")) {
+               g_test_fail ();
+               return;
+       }
+
+       test_utils_insert_content (fixture,
+               "<pre>line 1\n"
+               "line 2\n"
+               "line 3\n"
+               "</pre><span class=\"-x-evo-to-body\" data-credits=\"Credits:\"></span>"
+               "<span class=\"-x-evo-cite-body\"></span>",
+               E_CONTENT_EDITOR_INSERT_REPLACE_ALL | E_CONTENT_EDITOR_INSERT_TEXT_HTML);
+
+       if (!test_utils_run_simple_test (fixture,
+               "seq:uuuSesDbnnu\n"
+               "type:a very long text, which splits into multiple lines when this paragraph is not marked as 
preformatted, but as normal, as it should be\n"
+               "",
+               HTML_PREFIX "<div style=\"width: 71ch;\">Credits:</div>"
+               "<blockquote type=\"cite\">"
+               "<pre>&gt; line 1</pre>"
+               "</blockquote>"
+               "<div style=\"width: 71ch;\"><br></div>"
+               "<div style=\"width: 71ch;\">a very long text, which splits into multiple lines when this 
paragraph is not marked as preformatted, but as normal, as it should be</div>"
+               "<div style=\"width: 71ch;\"><br></div>"
+               "<blockquote type=\"cite\">"
+               "<pre>&gt; line 3</pre>"
+               "</blockquote>"
+               "<div style=\"width: 71ch;\"><br></div>"
+               HTML_SUFFIX,
+               "Credits:\n"
+               "> line 1\n"
+               "\n"
+               "a very long text, which splits into multiple lines when this paragraph\n"
+               "is not marked as preformatted, but as normal, as it should be\n"
+               "\n"
+               "> line 3\n"))
+               g_test_fail ();
+}
+
 void
 test_add_html_editor_bug_tests (void)
 {
@@ -850,4 +896,5 @@ test_add_html_editor_bug_tests (void)
        test_utils_add_test ("/bug/773164", test_bug_773164);
        test_utils_add_test ("/bug/775042", test_bug_775042);
        test_utils_add_test ("/bug/775691", test_bug_775691);
+       test_utils_add_test ("/bug/779707", test_bug_779707);
 }
diff --git a/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c 
b/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c
index 942770d..67bf33a 100644
--- a/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c
+++ b/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c
@@ -4059,6 +4059,68 @@ caret_is_on_the_line_beginning_html (WebKitDOMDocument *document)
 
        return ret_val;
 }
+
+static gboolean
+is_empty_quoted_element (WebKitDOMElement *element)
+{
+       WebKitDOMNode *node = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (element));
+
+       if (!WEBKIT_DOM_IS_ELEMENT (node) || !element_has_class (WEBKIT_DOM_ELEMENT (node), "-x-evo-quoted"))
+               return FALSE;
+
+       if (!(node = webkit_dom_node_get_next_sibling (node)))
+               return TRUE;
+
+       if (WEBKIT_DOM_IS_TEXT (node)) {
+               gchar *content;
+
+               content = webkit_dom_node_get_text_content (node);
+               if (content && *content) {
+                       g_free (content);
+                       return FALSE;
+               }
+
+               g_free (content);
+               return webkit_dom_node_get_next_sibling (node) ? FALSE : TRUE;
+       }
+
+       if (WEBKIT_DOM_IS_HTML_BR_ELEMENT (node))
+               return webkit_dom_node_get_next_sibling (node) ? FALSE : TRUE;
+
+       if (!WEBKIT_DOM_IS_ELEMENT (node) || !element_has_id (WEBKIT_DOM_ELEMENT (node), 
"-x-evo-selection-start-marker"))
+               return FALSE;
+
+       if (!(node = webkit_dom_node_get_next_sibling (node)))
+               return FALSE;
+
+       if (!WEBKIT_DOM_IS_ELEMENT (node) || !element_has_id (WEBKIT_DOM_ELEMENT (node), 
"-x-evo-selection-end-marker"))
+               return FALSE;
+
+       if (!(node = webkit_dom_node_get_next_sibling (node)))
+               return TRUE;
+
+       if (!WEBKIT_DOM_IS_HTML_BR_ELEMENT (node)) {
+               if (WEBKIT_DOM_IS_TEXT (node)) {
+                       gchar *content;
+
+                       content = webkit_dom_node_get_text_content (node);
+                       if (content && *content) {
+                               g_free (content);
+                               return FALSE;
+                       }
+
+                       g_free (content);
+                       return webkit_dom_node_get_next_sibling (node) ? FALSE : TRUE;
+               }
+               return FALSE;
+       }
+
+       if (!(node = webkit_dom_node_get_next_sibling (node)))
+               return TRUE;
+
+       return TRUE;
+}
+
 gboolean
 e_editor_dom_move_quoted_block_level_up (EEditorPage *editor_page)
 {
@@ -4140,10 +4202,12 @@ e_editor_dom_move_quoted_block_level_up (EEditorPage *editor_page)
        }
 
        if (citation_level == 1) {
+               gboolean is_empty_quoted_block = FALSE;
                gchar *inner_html = NULL;
                WebKitDOMElement *paragraph, *element;
 
                if (WEBKIT_DOM_IS_ELEMENT (block)) {
+                       is_empty_quoted_block = is_empty_quoted_element (WEBKIT_DOM_ELEMENT (block));
                        inner_html = webkit_dom_element_get_inner_html (WEBKIT_DOM_ELEMENT (block));
                        webkit_dom_element_set_id (WEBKIT_DOM_ELEMENT (block), "-x-evo-to-remove");
                }
@@ -4172,7 +4236,7 @@ e_editor_dom_move_quoted_block_level_up (EEditorPage *editor_page)
                        e_editor_dom_remove_wrapping_from_element (paragraph);
 
                        /* Moving PRE block from citation to body */
-                       if (WEBKIT_DOM_IS_HTML_PRE_ELEMENT (block)) {
+                       if (WEBKIT_DOM_IS_HTML_PRE_ELEMENT (block) && !is_empty_quoted_block) {
                                WebKitDOMElement *pre;
                                WebKitDOMNode *child;
 


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