[evolution] e-convert.js: Treat dash as a wrap-able character



commit 6c6ab536330b46a5a737dd71e08eac935285e6c8
Author: Milan Crha <mcrha redhat com>
Date:   Fri May 29 12:37:42 2020 +0200

    e-convert.js: Treat dash as a wrap-able character
    
    WebKit can wrap after the dash ('-'), similarly as before a space,
    thus let the EConvert to wrap in the same way.

 data/webkit/e-convert.js       | 23 +++++++++++++----------
 src/e-util/test-web-view-jsc.c | 30 ++++++++++++++++++++++++++++--
 2 files changed, 41 insertions(+), 12 deletions(-)
---
diff --git a/data/webkit/e-convert.js b/data/webkit/e-convert.js
index 22e576cc7a..4e10d5a451 100644
--- a/data/webkit/e-convert.js
+++ b/data/webkit/e-convert.js
@@ -369,7 +369,7 @@ EvoConvert.formatParagraph = function(str, ltr, align, indent, whiteSpace, wrapW
                        ignoreLineLetters : 0, // used for EvoConvert.NOWRAP_CHAR_START and 
EvoConvert.NOWRAP_CHAR_END, which should be skipped in width calculation
                        useWrapWidth : wrapWidth,
                        spacesFrom : -1, // in 'str'
-                       lastSpace : -1, // in this->line
+                       lastWrapableChar : -1, // in this->line
                        lineLetters : 0,
                        line : "",
 
@@ -404,10 +404,10 @@ EvoConvert.formatParagraph = function(str, ltr, align, indent, whiteSpace, wrapW
 
                        shouldWrap : function(nextChar) {
                                return this.canWrap && (!this.collapseWhiteSpace || nextChar != '\n') &&
-                                       (!this.isInUnwrapPart() || this.lastSpace != -1) && (this.lineLetters 
- this.ignoreLineLetters > this.useWrapWidth || (
+                                       (!this.isInUnwrapPart() || this.lastWrapableChar != -1) && 
(this.lineLetters - this.ignoreLineLetters > this.useWrapWidth || (
                                        ((!this.charWrap && (nextChar == " " || nextChar == "\t") && 
this.lineLetters - this.ignoreLineLetters > this.useWrapWidth) ||
                                        ((this.charWrap || (nextChar != " " && nextChar != "\t")) && 
this.lineLetters - this.ignoreLineLetters == this.useWrapWidth)) && (
-                                       this.lastSpace == -1/* || this.lastSpace == this.line.length*/)));
+                                       this.lastWrapableChar == -1/* || this.lastWrapableChar == 
this.line.length*/)));
                        },
 
                        commitSpaces : function(ii) {
@@ -427,9 +427,9 @@ EvoConvert.formatParagraph = function(str, ltr, align, indent, whiteSpace, wrapW
                                        }
 
                                        this.spacesFrom = -1;
-                                       this.lastSpace = this.line.length;
+                                       this.lastWrapableChar = this.line.length;
                                } else if (this.spacesFrom != -1) {
-                                       this.lastSpace = this.line.length;
+                                       this.lastWrapableChar = this.line.length;
                                }
                        },
 
@@ -438,9 +438,9 @@ EvoConvert.formatParagraph = function(str, ltr, align, indent, whiteSpace, wrapW
 
                                var didWrap = false;
 
-                               if (this.canWrap && this.lastSpace != -1 && this.lineLetters - 
this.ignoreLineLetters > this.useWrapWidth) {
-                                       lines[lines.length] = this.line.substr(0, this.lastSpace);
-                                       this.line = this.line.substr(this.lastSpace);
+                               if (this.canWrap && this.lastWrapableChar != -1 && this.lineLetters - 
this.ignoreLineLetters > this.useWrapWidth) {
+                                       lines[lines.length] = this.line.substr(0, this.lastWrapableChar);
+                                       this.line = this.line.substr(this.lastWrapableChar);
                                        this.maybeRecalcIgnoreLineLetters();
                                        didWrap = true;
                                } else if (!this.isInUnwrapPart() && this.useWrapWidth != -1 && 
this.lineLetters - this.ignoreLineLetters > this.useWrapWidth) {
@@ -493,7 +493,7 @@ EvoConvert.formatParagraph = function(str, ltr, align, indent, whiteSpace, wrapW
 
                                this.lineLetters = this.canWrap ? EvoConvert.calcLineLetters(this.line) : 
this.line.length;
                                this.spacesFrom = -1;
-                               this.lastSpace = -1;
+                               this.lastWrapableChar = -1;
                        }
                };
 
@@ -535,7 +535,7 @@ EvoConvert.formatParagraph = function(str, ltr, align, indent, whiteSpace, wrapW
                        } else if (!worker.charWrap && (chr == " " || chr == "\t")) {
                                var setSpacesFrom = false;
 
-                               if (chr == '\t') {
+                               if (chr == "\t") {
                                        worker.lineLetters = worker.lineLetters - ((worker.lineLetters - 
worker.ignoreLineLetters) % EvoConvert.TAB_WIDTH) + EvoConvert.TAB_WIDTH;
                                        setSpacesFrom = true;
                                } else if ((worker.spacesFrom == -1 && worker.line != "") || 
(!worker.collapseWhiteSpace && !worker.mayConsumeWhitespaceAfterWrap(str, ii))) {
@@ -563,6 +563,9 @@ EvoConvert.formatParagraph = function(str, ltr, align, indent, whiteSpace, wrapW
 
                                if (worker.shouldWrap(str[ii + 1]))
                                        worker.commit(ii, false);
+
+                               if (chr == "-" && worker.line.length && !worker.inAnchor)
+                                       worker.lastWrapableChar = worker.line.length;
                        }
                }
 
diff --git a/src/e-util/test-web-view-jsc.c b/src/e-util/test-web-view-jsc.c
index c58928a645..1627ec2015 100644
--- a/src/e-util/test-web-view-jsc.c
+++ b/src/e-util/test-web-view-jsc.c
@@ -2611,7 +2611,19 @@ test_convert_to_plain (TestFixture *fixture)
                "\n"
                "\n"
                "line6\n",
-               71 }
+               71 },
+       /* 67 */{ HTML ("<div>123 456-78 123456 7-890123 123-456-789- 1122------------- 789 
--------------------- 123</div>"),
+               "123 456-78\n"
+               "123456 7-\n"
+               "890123\n"
+               "123-456-\n"
+               "789- 1122-\n"
+               "----------\n"
+               "-- 789 ---\n"
+               "----------\n"
+               "--------\n"
+               "123\n",
+               10 }
        };
 
        #undef HTML
@@ -2950,7 +2962,21 @@ test_convert_to_plain_quoted (TestFixture *fixture)
                "> level 1 repeat\n"
                "level 0 back\n"
                "level 0 back nested\n",
-               71 }
+               71 },
+       /* 23 */{ HTML ("<blockquote type='cite'>"
+                       "<div>" QUOTE_SPAN (QUOTE_CHR) "123 456-78 123456 7-890123 123-456-789- 
1122------------- 789 --------------------- 123</div>"
+               "</blockquote>"),
+               "> 123 456-78\n"
+               "> 123456 7-\n"
+               "> 890123\n"
+               "> 123-456-\n"
+               "> 789- 1122-\n"
+               "> ----------\n"
+               "> -- 789 ---\n"
+               "> ----------\n"
+               "> --------\n"
+               "> 123\n",
+               12 }
        };
 
        #undef QUOTE_SPAN


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