[evolution] Composer: Various changes for Plain Text re-quote



commit 8565d0d68e4fda6ea0b0908a5d2d9ec1259e12a2
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jan 13 16:56:51 2022 +0100

    Composer: Various changes for Plain Text re-quote
    
    * Unlinkify mailto: anchors, which causes trouble on wrapping inside quoted text.
    * Merge consecutive text nodes before wrapping to simplify the algorithm

 data/webkit/e-editor.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 62 insertions(+), 4 deletions(-)
---
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index 4f0452cdaa..44a135f257 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -1942,6 +1942,44 @@ EvoEditor.getBlockquotePrefixHtml = function(blockquoteLevel)
        return prefixHtml;
 }
 
+EvoEditor.removeMailto = function(paragraph)
+{
+       var node, next, anyRemoved = false;
+       var selectionUpdater = EvoSelection.CreateUpdaterObject();
+
+       for (node = paragraph.firstChild; node; node = next) {
+               next = EvoEditor.getNextNodeInHierarchy(node, paragraph);
+
+               if (node.nodeType == node.ELEMENT_NODE && node.tagName == "A" &&
+                   node.href && node.href.toLowerCase().startsWith("mailto:";)) {
+                       var innerText = node.innerText, newNode;
+
+                       next = node.parentElement;
+
+                       if (innerText.length > 0) {
+                               var textNode = document.createTextNode(innerText);
+                               next.insertBefore(textNode, node);
+                               newNode = textNode;
+                       } else {
+                               newNode = node.nextSibling;
+                       }
+
+                       selectionUpdater.beforeRemove(node);
+
+                       node.remove();
+                       next = next.firstChild;
+                       anyRemoved = true;
+
+                       selectionUpdater.afterRemove(newNode);
+               }
+       }
+
+       if (anyRemoved)
+               selectionUpdater.restore();
+
+       return anyRemoved;
+}
+
 EvoEditor.quoteParagraph = function(paragraph, blockquoteLevel, wrapWidth)
 {
        if (!paragraph || !(blockquoteLevel > 0))
@@ -1952,13 +1990,26 @@ EvoEditor.quoteParagraph = function(paragraph, blockquoteLevel, wrapWidth)
        if (paragraph.tagName == "PRE")
                wrapWidth = -1;
 
-       var node = paragraph.firstChild, next, lineLength = 0;
+       var node, next, lineLength = 0;
+       var restoreMailto = EvoEditor.removeMailto(paragraph);
        var prefixHtml = EvoEditor.getBlockquotePrefixHtml(blockquoteLevel);
 
-       while (node) {
+       for (node = paragraph.firstChild; node; node = next) {
                next = EvoEditor.getNextNodeInHierarchy(node, paragraph);
 
                if (node.nodeType == node.TEXT_NODE) {
+                       if (node.nextSibling) {
+                               // merge consecutive text nodes into a single node, without calling 
normalize()
+                               var sibling;
+
+                               for (sibling = node.nextSibling; sibling && sibling.nodeType == 
sibling.TEXT_NODE; sibling = sibling.nextSibling) {
+                                       if (sibling.nodeValue != "") {
+                                               node.nodeValue = node.nodeValue + sibling.nodeValue;
+                                               sibling.nodeValue = "";
+                                       }
+                               }
+                       }
+
                        if (wrapWidth > 0 && lineLength + node.nodeValue.length > wrapWidth) {
                                lineLength = EvoEditor.quoteParagraphWrap(node, lineLength, wrapWidth, 
prefixHtml);
                        } else {
@@ -1989,11 +2040,18 @@ EvoEditor.quoteParagraph = function(paragraph, blockquoteLevel, wrapWidth)
                                next = node.nextSibling;
                        }
                }
-
-               node = next;
        }
 
        paragraph.insertAdjacentHTML("afterbegin", prefixHtml);
+
+       if (restoreMailto) {
+               for (node = paragraph.firstChild; node; node = next) {
+                       next = EvoEditor.getNextNodeInHierarchy(node, paragraph);
+
+                       if (node.nodeType == node.TEXT_NODE && node.parentElement.tagName != "A")
+                               EvoEditor.linkifyText(node, false);
+               }
+       }
 }
 
 EvoEditor.reBlockquotePlainText = function(plainText, usePreTag, isPreTag)


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