From c61022b00480ba0fe04084d5dd4a17fb98f484c1 Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Tue, 12 Oct 2021 16:13:45 +0200 Subject: [PATCH] I#1657 - Composer: Correct empty paragraph detection for removal Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/1657 --- data/webkit/e-editor.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js index 9c585c0241..b643f41548 100644 --- a/data/webkit/e-editor.js +++ b/data/webkit/e-editor.js @@ -3197,6 +3197,16 @@ EvoEditor.maybeRemoveQuotationMark = function(node) return true; } +EvoEditor.isQuotedElementEmpty = function(node) +{ + for (node = node.firstChild; node !== null; node = node.nextSibling) { + // the text inside is not empty + if (node.nodeType == node.TEXT_NODE && node.nodeValue !== null && node.nodeValue !== "") + return false; + } + return true; +} + EvoEditor.removeEmptyElements = function(tagName) { var nodes, node, ii, didRemove = 0; @@ -3215,9 +3225,7 @@ EvoEditor.removeEmptyElements = function(tagName) node.firstElementChild.className != "-x-evo-quoted")) continue; - // the text inside is not empty, possibly on either of the two sides of the quotation mark - if ((node.firstChild && (node.firstChild.nodeType == node.TEXT_NODE && node.firstChild.nodeValue)) || - (node.lastChild && !(node.lastChild === node.firstChild) && (node.lastChild.nodeType == node.TEXT_NODE && node.lastChild.nodeValue))) + if (!EvoEditor.isQuotedElementEmpty(node)) continue; // it's either completely empty or it contains only the quotation mark and nothing else