Vanessa 2025-02-05 10:21:23 +08:00
parent 9945bb3c75
commit dc7ccce10a

View File

@ -416,15 +416,13 @@ export class WYSIWYG {
} }
// 不能使用 commonAncestorContainer https://ld246.com/article/1643282894693 // 不能使用 commonAncestorContainer https://ld246.com/article/1643282894693
const codeBlockElement = hasClosestByAttribute(range.startContainer, "data-type", "NodeCodeBlock"); const codeBlockElement = hasClosestByAttribute(range.startContainer, "data-type", "NodeCodeBlock");
textPlain = tempElement.textContent;
if (codeBlockElement) { if (codeBlockElement) {
textPlain = tempElement.textContent.replace(Constants.ZWSP, "");
if (range.endContainer.textContent.length === range.endOffset && if (range.endContainer.textContent.length === range.endOffset &&
(range.endContainer.parentElement.getAttribute("spellcheck") ? !range.endContainer.nextSibling : !range.endContainer.parentElement.nextSibling)) { (range.endContainer.parentElement.getAttribute("spellcheck") ? !range.endContainer.nextSibling : !range.endContainer.parentElement.nextSibling)) {
textPlain = textPlain.replace(/\n$/, ""); textPlain = textPlain.replace(/\n$/, "");
} }
} else if (hasClosestByMatchTag(range.startContainer, "CODE")) { } else if (!hasClosestByMatchTag(range.startContainer, "CODE")) {
textPlain = tempElement.textContent.replace(Constants.ZWSP, "");
} else {
textPlain = range.toString(); textPlain = range.toString();
} }
} }