[evolution/wip/mcrha/webkit-jsc-api] html-editor: Signature's div content broken after format change



commit 35d1a46bebcddb4a5b4e3be99bf8a530872a2328
Author: Milan Crha <mcrha redhat com>
Date:   Wed Apr 22 10:11:29 2020 +0200

    html-editor: Signature's div content broken after format change

 data/webkit/e-convert.js |  5 ++++-
 data/webkit/e-editor.js  | 32 ++++++++++++++++++++++++++++----
 2 files changed, 32 insertions(+), 5 deletions(-)
---
diff --git a/data/webkit/e-convert.js b/data/webkit/e-convert.js
index 0431234a2b..7f7056e45a 100644
--- a/data/webkit/e-convert.js
+++ b/data/webkit/e-convert.js
@@ -776,7 +776,10 @@ EvoConvert.processNode = function(node, normalDivWidth, quoteLevel)
                        }
                }
        } else if (node.nodeType == node.ELEMENT_NODE) {
-               if (node.hidden || (node.tagName == "SPAN" && node.classList.contains("-x-evo-quoted")))
+               if (node.hidden ||
+                   node.tagName == "STYLE" ||
+                   node.tagName == "META" ||
+                   (node.tagName == "SPAN" && node.classList.contains("-x-evo-quoted")))
                        return str;
 
                var style = EvoConvert.getComputedOrNodeStyle(node), ltr, align, indent, whiteSpace;
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index 05872b3d17..8cf8217262 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -2062,7 +2062,7 @@ EvoEditor.moveNodeContent = function(node, intoNode)
                if (intoNode) {
                        intoNode.append(node.firstChild);
                } else {
-                       parent.insertBefore(node.firstChild, node.nextSibling);
+                       parent.insertBefore(node.firstChild, node);
                }
        }
 }
@@ -2137,7 +2137,11 @@ EvoEditor.convertTags = function()
                        }
                }
 
-               next = EvoEditor.getNextNodeInHierarchy(node, document.body);
+               // skip the signature wrapper
+               if (!removeNode && node.tagName == "DIV" && node.className == "-x-evo-signature-wrapper")
+                       next = node.nextSibling;
+               else
+                       next = EvoEditor.getNextNodeInHierarchy(node, document.body);
 
                if (removeNode)
                        node.remove();
@@ -4589,6 +4593,22 @@ EvoEditor.GetCurrentSignatureUid = function()
        return "";
 }
 
+EvoEditor.removeUnwantedTags = function(parent)
+{
+       if (!parent)
+               return;
+
+       var child, next = null;
+
+       for (child = parent.firstChild; child; child = next) {
+               next = child.nextSibling;
+
+               if (child.tagName == "STYLE" ||
+                   child.tagName == "META")
+                       child.remove();
+       }
+}
+
 EvoEditor.InsertSignature = function(content, isHTML, uid, fromMessage, checkChanged, ignoreNextChange, 
startBottom, topSignature, addDelimiter)
 {
        var sigSpan, node;
@@ -4602,6 +4622,8 @@ EvoEditor.InsertSignature = function(content, isHTML, uid, fromMessage, checkCha
                        node = document.createElement("SPAN");
                        node.innerHTML = content;
 
+                       EvoEditor.removeUnwantedTags(node);
+
                        content = EvoConvert.ToPlainText(node, EvoEditor.NORMAL_PARAGRAPH_WIDTH);
                        if (content != "") {
                                content = "<PRE>" + content.replace(/\&/g, "&amp;").replace(/</g, 
"&lt;").replace(/>/g, "&gt;") + "</PRE>";
@@ -4640,12 +4662,14 @@ EvoEditor.InsertSignature = function(content, isHTML, uid, fromMessage, checkCha
                        node.removeAttribute("[data-evo-signature-plain-text-mode]");
 
                node = sigSpan.querySelector("#-x-evo-selection-start-marker");
-               if (node && node.parentElement)
+               if (node)
                        node.remove();
 
                node = sigSpan.querySelector("#-x-evo-selection-end-marker");
-               if (node && node.parentElement)
+               if (node)
                        node.remove();
+
+               EvoEditor.removeUnwantedTags(sigSpan);
        }
 
        EvoUndoRedo.StartRecord(EvoUndoRedo.RECORD_KIND_GROUP, "InsertSignature");


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