From 83f23dae3fe66d33eab28d6997339321d7eecd54 Mon Sep 17 00:00:00 2001 From: Yi JiHong <0125ses@hanmail.net> Date: Sun, 11 Aug 2024 14:29:24 +0900 Subject: [PATCH] Fix: insertNode #1428 --- src/lib/core.js | 41 ++++++++------------------------ test/dev/suneditor_build_test.js | 7 +++--- 2 files changed, 13 insertions(+), 35 deletions(-) diff --git a/src/lib/core.js b/src/lib/core.js index 856fed7a..0bb0f5c5 100755 --- a/src/lib/core.js +++ b/src/lib/core.js @@ -1756,6 +1756,7 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re return null; } + let fNode = null; let range = this.getRange(); let line = util.isListCell(range.commonAncestorContainer) ? range.commonAncestorContainer : util.getFormatElement(this.getSelectionNode(), null); let insertListCell = util.isListCell(line) && (util.isListCell(oNode) || util.isList(oNode)); @@ -1958,9 +1959,10 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re } if (util.isWysiwygDiv(parentNode) && (oNode.nodeType === 3 || util.isBreak(oNode))) { - const fNode = util.createElement(options.defaultTag); - fNode.appendChild(oNode); - oNode = fNode; + const fomatNode = util.createElement(options.defaultTag); + fomatNode.appendChild(oNode); + fNode = oNode; + oNode = fomatNode; } } @@ -2018,6 +2020,8 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re parentNode.appendChild(oNode); console.warn('[SUNEDITOR.insertNode.warn] ' + error); } finally { + if (fNode) oNode = fNode; + const dupleNodes = parentNode.querySelectorAll('[data-se-duple]'); if (dupleNodes.length > 0) { for (let i = 0, len = dupleNodes.length, d, c, ch, parent; i < len; i++) { @@ -2049,30 +2053,8 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re if (!util.isComponent(oNode)) { let offset = 1; if (oNode.nodeType === 3) { - const previous = oNode.previousSibling; - const next = oNode.nextSibling; - const previousText = (!previous || previous.nodeType === 1 || util.onlyZeroWidthSpace(previous)) ? '' : previous.textContent; - const nextText = (!next || next.nodeType === 1 || util.onlyZeroWidthSpace(next)) ? '' : next.textContent; - - if (previous && previousText.length > 0) { - oNode.textContent = previousText + oNode.textContent; - util.removeItem(previous); - } - - if (next && next.length > 0) { - oNode.textContent += nextText; - util.removeItem(next); - } - - const newRange = { - container: oNode, - startOffset: previousText.length, - endOffset: oNode.textContent.length - nextText.length - }; - - this.setRange(oNode, newRange.startOffset, oNode, newRange.endOffset); - - return newRange; + offset = oNode.textContent.length; + this.setRange(oNode, offset, oNode, offset); } else if (!util.isBreak(oNode) && !util.isListCell(oNode) && util.isFormatElement(parentNode)) { let zeroWidth = null; if (!oNode.previousSibling || util.isBreak(oNode.previousSibling)) { @@ -2094,9 +2076,6 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re this.setRange(oNode, offset, oNode, offset); } - // history stack - this.history.push(true); - return oNode; } }, @@ -5320,7 +5299,7 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re r = style[i].match(/([a-zA-Z0-9-]+)(:)([^"']+)/); if (r && !/inherit|initial|revert|unset/i.test(r[3])) { const k = util.kebabToCamelCase(r[1].trim()); - const v = this.wwComputedStyle[k] ? this.wwComputedStyle[k].replace.(/"/g, '') : ''; + const v = this.wwComputedStyle[k] ? this.wwComputedStyle[k].replace(/"/g, '') : ''; const c = r[3].trim(); switch (k) { case 'fontFamily': diff --git a/test/dev/suneditor_build_test.js b/test/dev/suneditor_build_test.js index 4761204d..e609ee2b 100644 --- a/test/dev/suneditor_build_test.js +++ b/test/dev/suneditor_build_test.js @@ -1032,10 +1032,9 @@ let s2 = window.s2 = suneditor.create(document.getElementById('editor2'), { // addTagsWhitelist: "fld|sort|sortType|lst|lstfld|header|section", lineAttrReset: 'class', imageAccept: '*/*', - value: `
- -
Home Edge Logo
-
`, + value: `

Ôtez la complexité,
+M.Biz vous apporte des solutions utiles
+

`, // attributesWhitelist: { // all: 'style|class', // },