[evolution] Composer: UL/OL not wrapped properly in Plain Text mode



commit 461c01ad077647cb7e4ab841baf73833027fc27b
Author: Milan Crha <mcrha redhat com>
Date:   Wed Dec 2 13:57:19 2020 +0100

    Composer: UL/OL not wrapped properly in Plain Text mode
    
    In the Plain Text mode, when changing paragraph format to UL/OL, its width
    was not properly set, which drew the long lines unwrapped. Switching to HTML
    mode and back did set the expected wrap width.
    
    Similarly, when converting HTML into plain text (on send), the wrap width did
    not count width of the UL/OL prefix, making the line longer than it should be.

 data/webkit/e-convert.js                 |  24 ++++++-
 data/webkit/e-editor.js                  | 109 ++++++++++++++++++-------------
 src/e-util/test-html-editor-units-bugs.c |   4 +-
 src/e-util/test-html-editor-units.c      |  12 ++--
 4 files changed, 94 insertions(+), 55 deletions(-)
---
diff --git a/data/webkit/e-convert.js b/data/webkit/e-convert.js
index 503fbda1fd..7037ae9724 100644
--- a/data/webkit/e-convert.js
+++ b/data/webkit/e-convert.js
@@ -148,7 +148,7 @@ EvoConvert.getComputedOrNodeStyle = function(node)
        return node.style;
 }
 
-EvoConvert.replaceList = function(element, tagName)
+EvoConvert.replaceList = function(element, tagName, normalDivWidth)
 {
        var ll, lists, type = null;
 
@@ -269,6 +269,24 @@ EvoConvert.replaceList = function(element, tagName)
 
                                        if (Number.isInteger(width))
                                                node.style.width = "" + width + "ch";
+                               } else if (normalDivWidth > 0) {
+                                       var width, needs;
+
+                                       if (tagName == "UL") {
+                                               needs = 3;
+                                       } else {
+                                               needs = EvoConvert.GetOLMaxLetters(list.getAttribute("type"), 
list.children.length) + 2; // length of ". " suffix
+
+                                               if (needs < EvoConvert.MIN_OL_WIDTH)
+                                                       needs = EvoConvert.MIN_OL_WIDTH;
+                                       }
+
+                                       width = normalDivWidth - needs;
+
+                                       if (width < EvoConvert.MIN_PARAGRAPH_WIDTH)
+                                               width = EvoConvert.MIN_PARAGRAPH_WIDTH;
+
+                                       node.style.width = "" + width + "ch";
                                }
                                node.style.textAlign = list.style.testAlign;
                                node.style.direction = list.style.direction;
@@ -992,10 +1010,10 @@ EvoConvert.ToPlainText = function(element, normalDivWidth)
                        element = element.cloneNode(true);
 
                        if (uls.length)
-                               EvoConvert.replaceList(element, "UL");
+                               EvoConvert.replaceList(element, "UL", normalDivWidth);
 
                        if (ols.length)
-                               EvoConvert.replaceList(element, "OL");
+                               EvoConvert.replaceList(element, "OL", normalDivWidth);
                }
 
                for (ii = 0; ii < element.childNodes.length; ii++) {
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index 2601289e8c..ad39ad1161 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -1081,18 +1081,29 @@ EvoEditor.SetBlockFormat = function(format)
 
                        newElement = EvoEditor.renameElement(element, this.toSet.tagName, 
this.toSet.attributes, this.targetElement, this.selectionUpdater);
 
-                       if (EvoEditor.mode == EvoEditor.MODE_PLAIN_TEXT && (this.toSet.tagName == "DIV" || 
this.toSet.tagName == "PRE")) {
-                               var blockquoteLevel = EvoEditor.getBlockquoteLevel(newElement);
+                       if (EvoEditor.mode == EvoEditor.MODE_PLAIN_TEXT) {
+                               if (this.toSet.tagName == "DIV" || this.toSet.tagName == "PRE") {
+                                       var blockquoteLevel = EvoEditor.getBlockquoteLevel(newElement);
+
+                                       if (blockquoteLevel > 0) {
+                                               var width = -1;
+
+                                               if (this.toSet.tagName == "DIV" && blockquoteLevel * 2 < 
EvoEditor.NORMAL_PARAGRAPH_WIDTH)
+                                                       width = EvoEditor.NORMAL_PARAGRAPH_WIDTH - 
blockquoteLevel * 2;
 
-                               if (blockquoteLevel > 0) {
-                                       var width = -1;
+                                               EvoEditor.quoteParagraph(newElement, blockquoteLevel, width);
+                                       } else if (this.toSet.tagName == "DIV") {
+                                               newElement.setAttribute("style", "width: " + 
EvoEditor.NORMAL_PARAGRAPH_WIDTH + "ch;");
+                                       }
+                               } else if (this.toSet.tagName == "LI") {
+                                       var wrapWidth, blockquoteLevel = 
EvoEditor.getBlockquoteLevel(newElement);
+
+                                       wrapWidth = EvoEditor.NORMAL_PARAGRAPH_WIDTH - blockquoteLevel * 2;
 
-                                       if (this.toSet.tagName == "DIV" && blockquoteLevel * 2 < 
EvoEditor.NORMAL_PARAGRAPH_WIDTH)
-                                               width = EvoEditor.NORMAL_PARAGRAPH_WIDTH - blockquoteLevel * 
2;
+                                       if (wrapWidth <= 0)
+                                               wrapWidth = EvoEditor.NORMAL_PARAGRAPH_WIDTH;
 
-                                       EvoEditor.quoteParagraph(newElement, blockquoteLevel, width);
-                               } else if (this.toSet.tagName == "DIV") {
-                                       newElement.setAttribute("style", "width: " + 
EvoEditor.NORMAL_PARAGRAPH_WIDTH + "ch;");
+                                       EvoEditor.setULOLWidth(newElement.parentElement, wrapWidth);
                                }
                        }
 
@@ -1957,6 +1968,49 @@ EvoEditor.reBlockquotePlainText = function(plainText, usePreTag)
        return html;
 }
 
+EvoEditor.setULOLWidth = function(child, wrapWidth)
+{
+       if (!child)
+               return;
+
+       if (child.tagName == "UL") {
+               if (wrapWidth == -1) {
+                       child.style.width = "";
+                       EvoEditor.removeEmptyStyleAttribute(child);
+               } else {
+                       var innerWrapWidth = wrapWidth;
+
+                       innerWrapWidth -= 3; // length of " * " prefix
+
+                       if (innerWrapWidth < EvoConvert.MIN_PARAGRAPH_WIDTH)
+                               innerWrapWidth = EvoConvert.MIN_PARAGRAPH_WIDTH;
+
+                       child.style.width = innerWrapWidth + "ch";
+               }
+       } else if (child.tagName == "OL") {
+               if (wrapWidth == -1) {
+                       child.style.width = "";
+                       child.style.paddingInlineStart = "";
+                       EvoEditor.removeEmptyStyleAttribute(child);
+               } else {
+                       var innerWrapWidth = wrapWidth, olNeedWidth;
+
+                       olNeedWidth = EvoConvert.GetOLMaxLetters(child.getAttribute("type"), 
child.children.length) + 2; // length of ". " suffix
+
+                       if (olNeedWidth < EvoConvert.MIN_OL_WIDTH)
+                               olNeedWidth = EvoConvert.MIN_OL_WIDTH;
+
+                       innerWrapWidth -= olNeedWidth;
+
+                       if (innerWrapWidth < EvoConvert.MIN_PARAGRAPH_WIDTH)
+                               innerWrapWidth = EvoConvert.MIN_PARAGRAPH_WIDTH;
+
+                       child.style.width = innerWrapWidth + "ch";
+                       child.style.paddingInlineStart = olNeedWidth + "ch";
+               }
+       }
+}
+
 EvoEditor.convertParagraphs = function(parent, blockquoteLevel, wrapWidth, canChangeQuoteParagraphs)
 {
        if (!parent)
@@ -2028,41 +2082,8 @@ EvoEditor.convertParagraphs = function(parent, blockquoteLevel, wrapWidth, canCh
                        }
 
                        EvoEditor.convertParagraphs(child, blockquoteLevel + 1, innerWrapWidth, 
canChangeQuoteParagraphs);
-               } else if (child.tagName == "UL") {
-                       if (wrapWidth == -1) {
-                               child.style.width = "";
-                               EvoEditor.removeEmptyStyleAttribute(child);
-                       } else {
-                               var innerWrapWidth = wrapWidth;
-
-                               innerWrapWidth -= 3; // length of " * " prefix
-
-                               if (innerWrapWidth < EvoConvert.MIN_PARAGRAPH_WIDTH)
-                                       innerWrapWidth = EvoConvert.MIN_PARAGRAPH_WIDTH;
-
-                               child.style.width = innerWrapWidth + "ch";
-                       }
-               } else if (child.tagName == "OL") {
-                       if (wrapWidth == -1) {
-                               child.style.width = "";
-                               child.style.paddingInlineStart = "";
-                               EvoEditor.removeEmptyStyleAttribute(child);
-                       } else {
-                               var innerWrapWidth = wrapWidth, olNeedWidth;
-
-                               olNeedWidth = EvoConvert.GetOLMaxLetters(child.getAttribute("type"), 
child.children.length) + 2; // length of ". " suffix
-
-                               if (olNeedWidth < EvoConvert.MIN_OL_WIDTH)
-                                       olNeedWidth = EvoConvert.MIN_OL_WIDTH;
-
-                               innerWrapWidth -= olNeedWidth;
-
-                               if (innerWrapWidth < EvoConvert.MIN_PARAGRAPH_WIDTH)
-                                       innerWrapWidth = EvoConvert.MIN_PARAGRAPH_WIDTH;
-
-                               child.style.width = innerWrapWidth + "ch";
-                               child.style.paddingInlineStart = olNeedWidth + "ch";
-                       }
+               } else {
+                       EvoEditor.setULOLWidth(child, wrapWidth);
                }
        }
 }
diff --git a/src/e-util/test-html-editor-units-bugs.c b/src/e-util/test-html-editor-units-bugs.c
index 00bcaf3158..83844a063e 100644
--- a/src/e-util/test-html-editor-units-bugs.c
+++ b/src/e-util/test-html-editor-units-bugs.c
@@ -121,7 +121,7 @@ test_bug_767903 (TestFixture *fixture)
                "type:First item\\n\n"
                "type:Second item\n",
                HTML_PREFIX "<div style=\"width: 71ch;\">This is the first line:</div>"
-               "<ul>"
+               "<ul style=\"width: 68ch;\">"
                "<li>First item</li><li>Second item</li></ul>" HTML_SUFFIX,
                "This is the first line:\n"
                " * First item\n"
@@ -134,7 +134,7 @@ test_bug_767903 (TestFixture *fixture)
                "seq:uhb\n"
                "undo:undo\n",
                HTML_PREFIX "<div style=\"width: 71ch;\">This is the first line:</div>"
-               "<ul>"
+               "<ul style=\"width: 68ch;\">"
                "<li>First item</li><li>Second item</li></ul>" HTML_SUFFIX,
                "This is the first line:\n"
                " * First item\n"
diff --git a/src/e-util/test-html-editor-units.c b/src/e-util/test-html-editor-units.c
index 30270ca1b1..75ec24f3ff 100644
--- a/src/e-util/test-html-editor-units.c
+++ b/src/e-util/test-html-editor-units.c
@@ -3251,8 +3251,8 @@ test_list_indent_nested (TestFixture *fixture,
        unindented_plain =
                "line 1\n"
                " * a\n"
-               "      1. 123456789 123456789 123456789 123456789 123456789 123456789 123456789\n"
-               "         123456789\n"
+               "      1. 123456789 123456789 123456789 123456789 123456789 123456789\n"
+               "         123456789 123456789\n"
                "      2. 2\n"
                "          + x\n"
                "          + y\n"
@@ -3339,8 +3339,8 @@ test_list_indent_nested (TestFixture *fixture,
                HTML_SUFFIX,
                "line 1\n"
                "    - a\n"
-               "         1. 123456789 123456789 123456789 123456789 123456789 123456789 123456789\n"
-               "            123456789\n"
+               "         1. 123456789 123456789 123456789 123456789 123456789 123456789\n"
+               "            123456789 123456789\n"
                "         2. 2\n"
                "             * x\n"
                "             * y\n"
@@ -3410,8 +3410,8 @@ test_list_indent_nested (TestFixture *fixture,
                HTML_SUFFIX,
                "line 1\n"
                "a\n"
-               "   1. 123456789 123456789 123456789 123456789 123456789 123456789 123456789\n"
-               "      123456789\n"
+               "   1. 123456789 123456789 123456789 123456789 123456789 123456789\n"
+               "      123456789 123456789\n"
                "   2. 2\n"
                "       - x\n"
                "       - y\n"


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