[evolution/gnome-41] I#1708 - Composer: Wrap quoted long words



commit 186ea0ae5657c5b268097e995b874b9075df6996
Author: Milan Crha <mcrha redhat com>
Date:   Wed Nov 24 14:51:48 2021 +0100

    I#1708 - Composer: Wrap quoted long words
    
    Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/1708

 data/webkit/e-editor.js                  |  51 +++++++----
 src/e-util/test-html-editor-units-bugs.c | 146 ++++++++++++++++++++++++++++++-
 2 files changed, 177 insertions(+), 20 deletions(-)
---
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index b643f41548..5a3701519f 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -1832,24 +1832,44 @@ EvoEditor.quoteParagraphWrap = function(node, lineLength, wrapWidth, prefixHtml)
        var words = node.nodeValue.split(" "), ii, offset = 0, inc;
 
        for (ii = 0; ii < words.length; ii++) {
-               var word = words[ii], wordLen = word.length;
+               var word = words[ii], wordLen = word.length, eraseSpaceInSplit, firstHit = true;
+
+               while (lineLength + wordLen > wrapWidth) {
+                       eraseSpaceInSplit = true;
+
+                       if (offset == 0) {
+                               if (firstHit) {
+                                       firstHit = false;
+
+                                       var linkParts = EvoEditor.splitTextWithLinks(word);
+                                       // do not wrap links
+                                       if (linkParts != null && linkParts[0].href)
+                                               break;
+                               }
+
+                               eraseSpaceInSplit = false;
+                               offset = wrapWidth + 1;
+                               wordLen -= wrapWidth;
+                       }
 
-               if (lineLength + wordLen > wrapWidth) {
                        if (offset > 0) {
                                node.splitText(offset - 1);
                                node = node.nextSibling;
 
-                               // erase the space at the end of the line
-                               node.splitText(1);
-                               var next = node.nextSibling;
-                               node.remove();
-                               node = next;
+                               if (eraseSpaceInSplit) {
+                                       // erase the space at the end of the line
+                                       node.splitText(1);
+                                       var next = node.nextSibling;
+                                       node.remove();
+                                       node = next;
+                               }
 
                                // add the prefix and <br> only if there's still anything to be quoted
                                if (node.nodeValue.length > 0 || ii + 1 < words.length) {
                                        var br = document.createElement("BR");
                                        br.className = "-x-evo-wrap-br";
-                                       br.setAttribute("x-evo-is-space", "1");
+                                       if (eraseSpaceInSplit || (wordLen == 0 && ii + 1 < words.length))
+                                               br.setAttribute("x-evo-is-space", "1");
 
                                        node.parentElement.insertBefore(br, node);
 
@@ -2982,22 +3002,17 @@ EvoEditor.findSmileys = function(text, unicodeSmileys)
 EvoEditor.maybeUpdateParagraphWidth = function(topNode)
 {
        if (EvoEditor.mode == EvoEditor.MODE_PLAIN_TEXT) {
-               var node = topNode, citeLevel = 0;
+               var node = topNode, isCite = false;
 
-               while (node && node.tagName != "BODY") {
+               while (node && !isCite && node.tagName != "BODY") {
                        if (node.tagName == "BLOCKQUOTE")
-                               citeLevel++;
+                               isCite = true;
 
                        node = node.parentElement;
                }
 
-               if (citeLevel * 2 < EvoEditor.NORMAL_PARAGRAPH_WIDTH) {
-                       // to include the '> ' into the line length
-                       if (citeLevel >= 1)
-                               citeLevel--;
-
-                       topNode.style.width = (EvoEditor.NORMAL_PARAGRAPH_WIDTH - citeLevel * 2) + "ch";
-               }
+               if (!isCite)
+                       topNode.style.width = EvoEditor.NORMAL_PARAGRAPH_WIDTH + "ch";
        }
 }
 
diff --git a/src/e-util/test-html-editor-units-bugs.c b/src/e-util/test-html-editor-units-bugs.c
index c75b1fb6cb..8e1d0c83a1 100644
--- a/src/e-util/test-html-editor-units-bugs.c
+++ b/src/e-util/test-html-editor-units-bugs.c
@@ -2179,8 +2179,8 @@ test_issue_1157 (TestFixture *fixture)
                "action:paste\n",
                HTML_PREFIX "<div style=\"width: 12ch;\">Credits:</div>"
                "<blockquote type=\"cite\">"
-               "<div style=\"width: 12ch;\">" QUOTE_SPAN (QUOTE_CHR) "123 567 90</div>"
-               "<div style=\"width: 12ch;\">" QUOTE_SPAN (QUOTE_CHR) "2345678901</div>"
+               "<div>" QUOTE_SPAN (QUOTE_CHR) "123 567 90</div>"
+               "<div>" QUOTE_SPAN (QUOTE_CHR) "2345678901</div>"
                "</blockquote>"
                "<div style=\"width: 12ch;\"><a href=\"http://e.c/\";>http://e.c/</a></div>"
                HTML_SUFFIX,
@@ -2783,6 +2783,147 @@ test_issue_1392 (TestFixture *fixture)
                g_test_fail ();
 }
 
+static void
+test_issue_1708 (TestFixture *fixture)
+{
+       test_utils_fixture_change_setting_int32 (fixture, "org.gnome.evolution.mail", 
"composer-word-wrap-length", 10);
+
+       if (!test_utils_process_commands (fixture,
+               "mode:plain\n")) {
+               g_test_fail ();
+               return;
+       }
+
+       test_utils_insert_content (fixture,
+               "<body><div>aaa bbb ccc</div>"
+               "<div>1234567</div>"
+               "<div>dd 1234567</div>"
+               "<div>1234567 ee</div>"
+               "<div>ff 1234567 gg</div>"
+               "<div>12345678</div>"
+               "<div>12345678 hh</div>"
+               "<div>ii 12345678</div>"
+               "<div>jj 12345678 kk</div>"
+               "<div>1234567890123456</div>"
+               "<div>ll 1234567890123456</div>"
+               "<div>1234567890123456 mm</div>"
+               "<div>nn 1234567890123456 oo</div>"
+               "<div>123456789012345678901</div>"
+               "<div>pp 123456789012345678901</div>"
+               "<div>123456789012345678901 qq</div>"
+               "<div>rr 123456789012345678901 tt</div>"
+               "<div>uuu 123456789012345678901 vvv</div>"
+               "<span class=\"-x-evo-to-body\" data-credits=\"Credits:\"></span>"
+               "<span class=\"-x-evo-cite-body\"></span></body>",
+               E_CONTENT_EDITOR_INSERT_REPLACE_ALL | E_CONTENT_EDITOR_INSERT_TEXT_HTML);
+
+       if (!test_utils_run_simple_test (fixture,
+               "",
+               HTML_PREFIX "<div style=\"width: 10ch;\">Credits:</div>"
+               "<blockquote type=\"cite\">"
+               "<div>" QUOTE_SPAN (QUOTE_CHR) "aaa bbb" WRAP_BR_SPC
+               QUOTE_SPAN (QUOTE_CHR) "ccc</div>"
+               "<div>" QUOTE_SPAN (QUOTE_CHR) "1234567</div>"
+               "<div>" QUOTE_SPAN (QUOTE_CHR) "dd" WRAP_BR_SPC
+               QUOTE_SPAN (QUOTE_CHR) "1234567</div>"
+               "<div>" QUOTE_SPAN (QUOTE_CHR) "1234567" WRAP_BR_SPC
+               QUOTE_SPAN (QUOTE_CHR) "ee</div>"
+               "<div>" QUOTE_SPAN (QUOTE_CHR) "ff" WRAP_BR_SPC
+               QUOTE_SPAN (QUOTE_CHR) "1234567" WRAP_BR_SPC
+               QUOTE_SPAN (QUOTE_CHR) "gg</div>"
+               "<div>" QUOTE_SPAN (QUOTE_CHR) "12345678</div>"
+               "<div>" QUOTE_SPAN (QUOTE_CHR) "12345678" WRAP_BR_SPC
+               QUOTE_SPAN (QUOTE_CHR) "hh</div>"
+               "<div>" QUOTE_SPAN (QUOTE_CHR) "ii" WRAP_BR_SPC
+               QUOTE_SPAN (QUOTE_CHR) "12345678</div>"
+               "<div>" QUOTE_SPAN (QUOTE_CHR) "jj" WRAP_BR_SPC
+               QUOTE_SPAN (QUOTE_CHR) "12345678" WRAP_BR_SPC
+               QUOTE_SPAN (QUOTE_CHR) "kk</div>"
+               "<div>" QUOTE_SPAN (QUOTE_CHR) "12345678" WRAP_BR
+               QUOTE_SPAN (QUOTE_CHR) "90123456</div>"
+               "<div>" QUOTE_SPAN (QUOTE_CHR) "ll" WRAP_BR_SPC
+               QUOTE_SPAN (QUOTE_CHR) "12345678" WRAP_BR
+               QUOTE_SPAN (QUOTE_CHR) "90123456</div>"
+               "<div>" QUOTE_SPAN (QUOTE_CHR) "12345678" WRAP_BR
+               QUOTE_SPAN (QUOTE_CHR) "90123456" WRAP_BR_SPC
+               QUOTE_SPAN (QUOTE_CHR) "mm</div>"
+               "<div>" QUOTE_SPAN (QUOTE_CHR) "nn" WRAP_BR_SPC
+               QUOTE_SPAN (QUOTE_CHR) "12345678" WRAP_BR
+               QUOTE_SPAN (QUOTE_CHR) "90123456" WRAP_BR_SPC
+               QUOTE_SPAN (QUOTE_CHR) "oo</div>"
+               "<div>" QUOTE_SPAN (QUOTE_CHR) "12345678" WRAP_BR
+               QUOTE_SPAN (QUOTE_CHR) "90123456" WRAP_BR
+               QUOTE_SPAN (QUOTE_CHR) "78901</div>"
+               "<div>" QUOTE_SPAN (QUOTE_CHR) "pp" WRAP_BR_SPC
+               QUOTE_SPAN (QUOTE_CHR) "12345678" WRAP_BR
+               QUOTE_SPAN (QUOTE_CHR) "90123456" WRAP_BR
+               QUOTE_SPAN (QUOTE_CHR) "78901</div>"
+               "<div>" QUOTE_SPAN (QUOTE_CHR) "12345678" WRAP_BR
+               QUOTE_SPAN (QUOTE_CHR) "90123456" WRAP_BR
+               QUOTE_SPAN (QUOTE_CHR) "78901 qq</div>"
+               "<div>" QUOTE_SPAN (QUOTE_CHR) "rr" WRAP_BR_SPC
+               QUOTE_SPAN (QUOTE_CHR) "12345678" WRAP_BR
+               QUOTE_SPAN (QUOTE_CHR) "90123456" WRAP_BR
+               QUOTE_SPAN (QUOTE_CHR) "78901 tt</div>"
+               "<div>" QUOTE_SPAN (QUOTE_CHR) "uuu" WRAP_BR_SPC
+               QUOTE_SPAN (QUOTE_CHR) "12345678" WRAP_BR
+               QUOTE_SPAN (QUOTE_CHR) "90123456" WRAP_BR
+               QUOTE_SPAN (QUOTE_CHR) "78901" WRAP_BR_SPC
+               QUOTE_SPAN (QUOTE_CHR) "vvv</div>"
+               "</blockquote>"
+               HTML_SUFFIX,
+               "Credits:\n"
+               "> aaa bbb\n"
+               "> ccc\n"
+               "> 1234567\n"
+               "> dd\n"
+               "> 1234567\n"
+               "> 1234567\n"
+               "> ee\n"
+               "> ff\n"
+               "> 1234567\n"
+               "> gg\n"
+               "> 12345678\n"
+               "> 12345678\n"
+               "> hh\n"
+               "> ii\n"
+               "> 12345678\n"
+               "> jj\n"
+               "> 12345678\n"
+               "> kk\n"
+               "> 12345678\n"
+               "> 90123456\n"
+               "> ll\n"
+               "> 12345678\n"
+               "> 90123456\n"
+               "> 12345678\n"
+               "> 90123456\n"
+               "> mm\n"
+               "> nn\n"
+               "> 12345678\n"
+               "> 90123456\n"
+               "> oo\n"
+               "> 12345678\n"
+               "> 90123456\n"
+               "> 78901\n"
+               "> pp\n"
+               "> 12345678\n"
+               "> 90123456\n"
+               "> 78901\n"
+               "> 12345678\n"
+               "> 90123456\n"
+               "> 78901 qq\n"
+               "> rr\n"
+               "> 12345678\n"
+               "> 90123456\n"
+               "> 78901 tt\n"
+               "> uuu\n"
+               "> 12345678\n"
+               "> 90123456\n"
+               "> 78901\n"
+               "> vvv\n"))
+               g_test_fail ();
+}
 void
 test_add_html_editor_bug_tests (void)
 {
@@ -2831,4 +2972,5 @@ test_add_html_editor_bug_tests (void)
        test_utils_add_test ("/issue/1424-level2", test_issue_1424_level2);
        test_utils_add_test ("/issue/1439", test_issue_1439);
        test_utils_add_test ("/issue/1392", test_issue_1392);
+       test_utils_add_test ("/issue/1708", test_issue_1708);
 }


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