[evolution/wip/mcrha/webkit-jsc-api] e-convert.js: Skip leading insignificant new line characters in text



commit 801af40d94aa3f5506d61c320d5b6b0f7a6dcac9
Author: Milan Crha <mcrha redhat com>
Date:   Thu Apr 16 14:15:14 2020 +0200

    e-convert.js: Skip leading insignificant new line characters in text

 data/webkit/e-convert.js       | 19 +++++++++++++------
 src/e-util/test-web-view-jsc.c | 16 +++++++++++++++-
 2 files changed, 28 insertions(+), 7 deletions(-)
---
diff --git a/data/webkit/e-convert.js b/data/webkit/e-convert.js
index 93440d2359..ca871170c0 100644
--- a/data/webkit/e-convert.js
+++ b/data/webkit/e-convert.js
@@ -370,7 +370,6 @@ EvoConvert.formatParagraph = function(str, ltr, align, indent, whiteSpace, wrapW
                        useWrapWidth : wrapWidth,
                        spacesFrom : -1, // in 'str'
                        lastSpace : -1, // in this->line
-                       lastWasWholeLine : false, // to distinguish between new line in the text and new line 
from wrapping with while line text
                        lineLetters : 0,
                        line : "",
 
@@ -472,12 +471,9 @@ EvoConvert.formatParagraph = function(str, ltr, align, indent, whiteSpace, wrapW
                                        worker.line = worker.line.substr(jj);
                                        worker.maybeRecalcIgnoreLineLetters();
                                        didWrap = true;
-                               } else if (worker.collapseWhiteSpace && worker.lastWasWholeLine && 
worker.line == "") {
-                                       worker.lastWasWholeLine = false;
                                } else {
                                        lines[lines.length] = worker.line;
                                        worker.line = "";
-                                       worker.lastWasWholeLine = true;
                                        worker.ignoreLineLetters = 0;
                                }
 
@@ -748,10 +744,21 @@ EvoConvert.processNode = function(node, normalDivWidth, quoteLevel)
                        if (whiteSpace == "pre-line") {
                                str = EvoConvert.mergeConsecutiveSpaces(str.replace(/\t/g, " "));
                        } else if (!whiteSpace || whiteSpace == "normal" || whiteSpace == "nowrap") {
-                               if (str == "\n" || str == "\r" || str == "\r\n")
+                               if (str == "\n" || str == "\r" || str == "\r\n") {
                                        str = "";
-                               else
+                               } else {
+                                       if ((!node.previousSibling || node.previousSibling.tagName) && 
(str[0] == '\r' || str[0] == '\n')) {
+                                               var ii;
+
+                                               for (ii = 0; str[ii] == '\n' || str[ii] == '\r'; ii++) {
+                                                       // do nothing, just skip all leading insignificant 
new lines
+                                               }
+
+                                               str = str.substr(ii);
+                                       }
+
                                        str = EvoConvert.mergeConsecutiveSpaces(str.replace(/\t/g, " 
").replace(/\r/g, " ").replace(/\n/g, " "));
+                               }
                        }
                }
        } else if (node.nodeType == node.ELEMENT_NODE) {
diff --git a/src/e-util/test-web-view-jsc.c b/src/e-util/test-web-view-jsc.c
index 17bff71041..3683716ecb 100644
--- a/src/e-util/test-web-view-jsc.c
+++ b/src/e-util/test-web-view-jsc.c
@@ -2597,7 +2597,21 @@ test_convert_to_plain (TestFixture *fixture)
                "text before\n"
                "https://no.where/1234567890/123457890/1234567890\n";
                "text after\n",
-               12 }
+               12 },
+       /* 66 */{ HTML ("<div>line1<br>\n"
+               "line2<br>\n"
+               "line3<br>\n"
+               "<br>\n"
+               "<br>\n"
+               "line6<br>\n"
+               "</div>"),
+               "line1\n"
+               "line2\n"
+               "line3\n"
+               "\n"
+               "\n"
+               "line6\n",
+               71 }
        };
 
        #undef HTML


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