[evolution/gnome-3-22] Don't preserve 'Preformatted' format if moving an empty block out of the quoted content



commit dfe0bead0389ff37e5122362697be31fd130e261
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.

 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/e-util/test-html-editor-units-bugs.c b/e-util/test-html-editor-units-bugs.c
index 3459ad6..33dae70 100644
--- a/e-util/test-html-editor-units-bugs.c
+++ b/e-util/test-html-editor-units-bugs.c
@@ -831,6 +831,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)
 {
@@ -852,4 +898,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/modules/webkit-editor/web-extension/e-editor-dom-functions.c 
b/modules/webkit-editor/web-extension/e-editor-dom-functions.c
index b29d4d3..c669176 100644
--- a/modules/webkit-editor/web-extension/e-editor-dom-functions.c
+++ b/modules/webkit-editor/web-extension/e-editor-dom-functions.c
@@ -4061,6 +4061,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)
 {
@@ -4142,10 +4204,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");
                }
@@ -4174,7 +4238,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]