Vanessa 2025-02-04 21:55:49 +08:00
parent d663064b39
commit 9945bb3c75

View file

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