Skip to content

Commit

Permalink
Fix: insertNode JiHong88#1428
Browse files Browse the repository at this point in the history
  • Loading branch information
JiHong88 authored and onedark23 committed Aug 12, 2024
1 parent 2fafa49 commit 2455598
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 35 deletions.
41 changes: 10 additions & 31 deletions src/lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,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));
Expand Down Expand Up @@ -1963,9 +1964,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;
}
}

Expand Down Expand Up @@ -2023,6 +2025,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++) {
Expand Down Expand Up @@ -2054,30 +2058,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)) {
Expand All @@ -2099,9 +2081,6 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
this.setRange(oNode, offset, oNode, offset);
}

// history stack
this.history.push(true);

return oNode;
}
},
Expand Down Expand Up @@ -5325,7 +5304,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':
Expand Down
7 changes: 3 additions & 4 deletions test/dev/suneditor_build_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: `<figure>
<img src="https://blog.kakaocdn.net/dn/0QCnX/btqU7cMuFOZ/uVPVj1aIBNqINLQZGkuwa0/img.png" alt="">
<figcaption>Home Edge Logo</figcaption>
</figure>`,
value: `<p>Ôtez la <span style="color: rgb(235, 141, 117)">complexité</span>,<br>
M.Biz vous apporte des solutions utiles<br>
</p>`,
// attributesWhitelist: {
// all: 'style|class',
// },
Expand Down

0 comments on commit 2455598

Please sign in to comment.