From d8fcd6528681b5eb13a092864a5d80977eaa3d1f Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Thu, 29 Jan 2026 01:10:56 +0100 Subject: [PATCH] Button Update remove Lines --- config/current.ver | 2 +- public/assets/js/bridge/rte-editor.js | 132 +++++++++++++++----------- 2 files changed, 75 insertions(+), 59 deletions(-) diff --git a/config/current.ver b/config/current.ver index 66aafdf..a8c3a67 100644 --- a/config/current.ver +++ b/config/current.ver @@ -1 +1 @@ -1.1.56 \ No newline at end of file +1.1.57 \ No newline at end of file diff --git a/public/assets/js/bridge/rte-editor.js b/public/assets/js/bridge/rte-editor.js index 4cb8dd2..746379b 100644 --- a/public/assets/js/bridge/rte-editor.js +++ b/public/assets/js/bridge/rte-editor.js @@ -560,42 +560,50 @@ const docRef = content.ownerDocument || document; const range = getSelectionRange(); if (!range || range.collapsed) return; - const fragment = range.extractContents(); const unwrap = (node) => { const parent = node.parentNode; if (!parent) return; while (node.firstChild) parent.insertBefore(node.firstChild, node); parent.removeChild(node); }; - const strip = (node) => { - if (!node) return; - if (node.nodeType === 1) { - const tag = node.tagName ? node.tagName.toUpperCase() : ''; - if (tags && tags.includes(tag)) { - const children = Array.from(node.childNodes); - children.forEach(strip); - unwrap(node); - return; - } - if (styleProp && node.style) { - if (typeof clearFn === 'function') { - clearFn(node.style); - } else { - node.style[styleProp] = ''; - } - const styleAttr = node.getAttribute('style'); - if (!styleAttr || !String(styleAttr).trim()) { - const children = Array.from(node.childNodes); - children.forEach(strip); - unwrap(node); - return; - } - } - Array.from(node.childNodes).forEach(strip); + const depth = (node) => { + let d = 0; + let cur = node; + while (cur && cur !== content) { + d += 1; + cur = cur.parentNode; } + return d; }; - Array.from(fragment.childNodes).forEach(strip); - range.insertNode(fragment); + const nodes = []; + const walker = docRef.createTreeWalker(content, NodeFilter.SHOW_ELEMENT, null); + let node = walker.nextNode(); + while (node) { + if (node !== content && range.intersectsNode(node)) { + nodes.push(node); + } + node = walker.nextNode(); + } + nodes.sort((a, b) => depth(b) - depth(a)); + nodes.forEach((el) => { + const tag = el.tagName ? el.tagName.toUpperCase() : ''; + if (tag === 'BR') return; + if (tags && tags.includes(tag)) { + unwrap(el); + return; + } + if (styleProp && el.style) { + if (typeof clearFn === 'function') { + clearFn(el.style); + } else { + el.style[styleProp] = ''; + } + const styleAttr = el.getAttribute('style'); + if ((!styleAttr || !String(styleAttr).trim()) && tag === 'SPAN') { + unwrap(el); + } + } + }); saveSelection(); } catch {} }; @@ -617,44 +625,52 @@ const docRef = content.ownerDocument || document; const range = getSelectionRange(); if (!range || range.collapsed) return; - const fragment = range.extractContents(); const unwrap = (node) => { const parent = node.parentNode; if (!parent) return; while (node.firstChild) parent.insertBefore(node.firstChild, node); parent.removeChild(node); }; - const strip = (node) => { - if (!node) return; - if (node.nodeType === 1) { - const tag = node.tagName ? node.tagName.toUpperCase() : ''; - if (tag === 'B' || tag === 'STRONG' || tag === 'I' || tag === 'EM' || tag === 'U' || tag === 'S' || tag === 'STRIKE') { - const children = Array.from(node.childNodes); - children.forEach(strip); - unwrap(node); - return; - } - if (tag === 'SPAN') { - try { - node.style.fontWeight = ''; - node.style.fontStyle = ''; - node.style.textDecoration = ''; - node.style.textDecorationLine = ''; - node.style.textDecorationStyle = ''; - } catch {} - const styleAttr = node.getAttribute('style'); - if (!styleAttr || !String(styleAttr).trim()) { - const children = Array.from(node.childNodes); - children.forEach(strip); - unwrap(node); - return; - } - } - Array.from(node.childNodes).forEach(strip); + const depth = (node) => { + let d = 0; + let cur = node; + while (cur && cur !== content) { + d += 1; + cur = cur.parentNode; } + return d; }; - Array.from(fragment.childNodes).forEach(strip); - range.insertNode(fragment); + const nodes = []; + const walker = docRef.createTreeWalker(content, NodeFilter.SHOW_ELEMENT, null); + let node = walker.nextNode(); + while (node) { + if (node !== content && range.intersectsNode(node)) { + nodes.push(node); + } + node = walker.nextNode(); + } + nodes.sort((a, b) => depth(b) - depth(a)); + nodes.forEach((el) => { + const tag = el.tagName ? el.tagName.toUpperCase() : ''; + if (tag === 'BR') return; + if (tag === 'B' || tag === 'STRONG' || tag === 'I' || tag === 'EM' || tag === 'U' || tag === 'S' || tag === 'STRIKE') { + unwrap(el); + return; + } + if (tag === 'SPAN') { + try { + el.style.fontWeight = ''; + el.style.fontStyle = ''; + el.style.textDecoration = ''; + el.style.textDecorationLine = ''; + el.style.textDecorationStyle = ''; + } catch {} + const styleAttr = el.getAttribute('style'); + if (!styleAttr || !String(styleAttr).trim()) { + unwrap(el); + } + } + }); saveSelection(); } catch {} };