[evolution] I#913 - Switching to plain-text keeps signature's HTML formatting



commit 2001ba51d89eda1e1bae4929c3370ffe2b7a62c6
Author: Milan Crha <mcrha redhat com>
Date:   Tue Nov 3 13:37:48 2020 +0100

    I#913 - Switching to plain-text keeps signature's HTML formatting
    
    Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/913

 data/webkit/e-editor.js                   | 18 ++++----
 src/e-util/test-html-editor-units-bugs.c  | 75 +++++++++++++++++++++++++++++++
 src/e-util/test-html-editor-units-utils.c | 73 +++++++++++++++++++++++++++++-
 src/e-util/test-html-editor-units-utils.h |  7 +++
 4 files changed, 164 insertions(+), 9 deletions(-)
---
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index e682540049..cec287d7ec 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -2077,9 +2077,9 @@ EvoEditor.SetNormalParagraphWidth = function(value)
 EvoEditor.moveNodeContent = function(node, intoNode)
 {
        if (!node || !node.parentElement)
-               return;
+               return null;
 
-       var parent = node.parentElement;
+       var parent = node.parentElement, firstChild = node.firstChild;
 
        while (node.firstChild) {
                if (intoNode) {
@@ -2088,6 +2088,8 @@ EvoEditor.moveNodeContent = function(node, intoNode)
                        parent.insertBefore(node.firstChild, node);
                }
        }
+
+       return firstChild;
 }
 
 EvoEditor.convertTags = function()
@@ -2134,7 +2136,10 @@ EvoEditor.convertTags = function()
        while (node) {
                var removeNode = false;
 
-               if (node.nodeType == node.ELEMENT_NODE) {
+               next = null;
+
+               /* Keep the signature SPAN there, it's required */
+               if (node.nodeType == node.ELEMENT_NODE && (node.tagName != "SPAN" || node.className != 
"-x-evo-signature")) {
                        if (node.tagName != "DIV" &&
                            node.tagName != "PRE" &&
                            node.tagName != "BLOCKQUOTE" &&
@@ -2150,15 +2155,12 @@ EvoEditor.convertTags = function()
                                        EvoEditor.moveNodeContent(node, div);
                                        node.parentElement.insertBefore(div, node.nextSibling);
                                } else {
-                                       EvoEditor.moveNodeContent(node);
+                                       next = EvoEditor.moveNodeContent(node);
                                }
                        }
                }
 
-               // skip the signature wrapper
-               if (!removeNode && node.tagName == "DIV" && node.className == "-x-evo-signature-wrapper")
-                       next = node.nextSibling;
-               else
+               if (!next)
                        next = EvoEditor.getNextNodeInHierarchy(node, document.body);
 
                if (removeNode)
diff --git a/src/e-util/test-html-editor-units-bugs.c b/src/e-util/test-html-editor-units-bugs.c
index 15196b327d..a23af4051d 100644
--- a/src/e-util/test-html-editor-units-bugs.c
+++ b/src/e-util/test-html-editor-units-bugs.c
@@ -1969,6 +1969,80 @@ test_issue_1197 (TestFixture *fixture)
        }
 }
 
+static void
+test_issue_913 (TestFixture *fixture)
+{
+       if (!test_utils_process_commands (fixture,
+               "mode:html\n")) {
+               g_test_fail ();
+               return;
+       }
+
+       if (!test_utils_run_simple_test (fixture,
+               "type:aa \n"
+               "action:size-plus-two\n"
+               "type:bb \n"
+               "action:bold\n"
+               "type:cc\n"
+               "action:bold\n"
+               "type: dd\n"
+               "action:size-plus-zero\n"
+               "type:\\nee\n",
+               HTML_PREFIX
+               "<div>aa <font size=\"5\">bb <b>cc</b> dd</font></div>"
+               "<div><font size=\"3\">ee</font></div>"
+               HTML_SUFFIX,
+               "aa bb cc dd\n"
+               "ee\n")) {
+               g_test_fail ();
+               return;
+       }
+
+       test_utils_insert_signature (fixture,
+               "<div>tt <b>uu <i>vv</i> <font size=\"2\">ww</font> xx</b> yy</div>",
+               TRUE, "UID", FALSE, FALSE, TRUE);
+
+       if (!test_utils_run_simple_test (fixture,
+               "",
+               HTML_PREFIX
+               "<div>aa <font size=\"5\">bb <b>cc</b> dd</font></div>"
+               "<div><font size=\"3\">ee</font></div>"
+               "<div><br></div>"
+               "<div class=\"-x-evo-signature-wrapper\"><span class=\"-x-evo-signature\" id=\"UID\">"
+               "<pre>-- <br></pre>"
+               "<div>tt <b>uu <i>vv</i> <font size=\"2\">ww</font> xx</b> yy</div>"
+               "</span></div>"
+               HTML_SUFFIX,
+               "aa bb cc dd\n"
+               "ee\n"
+               "\n"
+               "-- \n"
+               "tt uu vv ww xx yy\n")) {
+               g_test_fail ();
+               return;
+       }
+
+       if (!test_utils_run_simple_test (fixture,
+               "mode:plain\n",
+               HTML_PREFIX
+               "<div style=\"width: 71ch;\">aa bb cc dd</div>"
+               "<div style=\"width: 71ch;\">ee</div>"
+               "<div style=\"width: 71ch;\"><br></div>"
+               "<div style=\"width: 71ch;\" class=\"-x-evo-signature-wrapper\"><span 
class=\"-x-evo-signature\" id=\"UID\">"
+               "<pre>-- <br></pre>"
+               "<div>tt uu vv ww xx yy</div>"
+               "</span></div>"
+               HTML_SUFFIX,
+               "aa bb cc dd\n"
+               "ee\n"
+               "\n"
+               "-- \n"
+               "tt uu vv ww xx yy\n")) {
+               g_test_fail ();
+               return;
+       }
+}
+
 void
 test_add_html_editor_bug_tests (void)
 {
@@ -2004,4 +2078,5 @@ test_add_html_editor_bug_tests (void)
        test_utils_add_test ("/issue/884", test_issue_884);
        test_utils_add_test ("/issue/783", test_issue_783);
        test_utils_add_test ("/issue/1197", test_issue_1197);
+       test_utils_add_test ("/issue/913", test_issue_913);
 }
diff --git a/src/e-util/test-html-editor-units-utils.c b/src/e-util/test-html-editor-units-utils.c
index 309176bc2d..929763bcbf 100644
--- a/src/e-util/test-html-editor-units-utils.c
+++ b/src/e-util/test-html-editor-units-utils.c
@@ -773,7 +773,7 @@ test_utils_html_equal (TestFixture *fixture,
                "}\n"
                "EvoEditorTest.isHTMLEqual(%s, %s);", html1, html2);
 
-       hed.async_data = test_utils_async_call_prepare();
+       hed.async_data = test_utils_async_call_prepare ();
        hed.equal = FALSE;
 
        webkit_web_view_run_javascript (WEBKIT_WEB_VIEW (cnt_editor), script, NULL,
@@ -1333,3 +1333,74 @@ test_utils_dup_image_uri (const gchar *path)
 
        return image_uri;
 }
+
+static void
+test_utils_insert_signature_done_cb (GObject *source_object,
+                                    GAsyncResult *result,
+                                    gpointer user_data)
+{
+       gpointer async_data = user_data;
+       WebKitJavascriptResult *js_result;
+       JSCException *exception;
+       JSCValue *js_value;
+       GError *error = NULL;
+
+       g_return_if_fail (async_data != NULL);
+
+       js_result = webkit_web_view_run_javascript_finish (WEBKIT_WEB_VIEW (source_object), result, &error);
+
+       g_assert_no_error (error);
+       g_clear_error (&error);
+
+       g_assert_nonnull (js_result);
+
+       js_value = webkit_javascript_result_get_js_value (js_result);
+       g_assert_nonnull (js_value);
+
+       exception = jsc_context_get_exception (jsc_value_get_context (js_value));
+
+       if (exception) {
+               g_warning ("Failed to call EvoEditor.InsertSignature: %s", jsc_exception_get_message 
(exception));
+               jsc_context_clear_exception (jsc_value_get_context (js_value));
+       }
+
+       webkit_javascript_result_unref (js_result);
+
+       test_utils_async_call_finish (async_data);
+}
+
+void
+test_utils_insert_signature (TestFixture *fixture,
+                            const gchar *content,
+                            gboolean is_html,
+                            const gchar *uid,
+                            gboolean start_bottom,
+                            gboolean top_signature,
+                            gboolean add_delimiter)
+{
+       EContentEditor *cnt_editor;
+       gchar *script;
+       gpointer async_data;
+
+       g_return_if_fail (fixture != NULL);
+       g_return_if_fail (E_IS_HTML_EDITOR (fixture->editor));
+       g_return_if_fail (content != NULL);
+       g_return_if_fail (uid != NULL);
+
+       cnt_editor = e_html_editor_get_content_editor (fixture->editor);
+       g_return_if_fail (cnt_editor != NULL);
+       g_return_if_fail (WEBKIT_IS_WEB_VIEW (cnt_editor));
+
+       script = e_web_view_jsc_printf_script (
+               "EvoEditor.InsertSignature(%s, %x, false, %s, false, false, true, %x, %x, %x);",
+               content, is_html, uid, start_bottom, top_signature, add_delimiter);
+
+       async_data = test_utils_async_call_prepare ();
+
+       webkit_web_view_run_javascript (WEBKIT_WEB_VIEW (cnt_editor), script, NULL,
+               test_utils_insert_signature_done_cb, async_data);
+
+       test_utils_async_call_wait (async_data, 10);
+
+       g_free (script);
+}
diff --git a/src/e-util/test-html-editor-units-utils.h b/src/e-util/test-html-editor-units-utils.h
index a24ba56033..fe9f36ebff 100644
--- a/src/e-util/test-html-editor-units-utils.h
+++ b/src/e-util/test-html-editor-units-utils.h
@@ -106,6 +106,13 @@ gchar *            test_utils_get_clipboard_text   (gboolean request_html);
 EContentEditor *
                test_utils_get_content_editor   (TestFixture *fixture);
 gchar *                test_utils_dup_image_uri        (const gchar *path);
+void           test_utils_insert_signature     (TestFixture *fixture,
+                                                const gchar *content,
+                                                gboolean is_html,
+                                                const gchar *uid,
+                                                gboolean start_bottom,
+                                                gboolean top_signature,
+                                                gboolean add_delimiter);
 
 G_END_DECLS
 


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