From 9945bb3c75bed46784fe25bd43a8cdeec41496db Mon Sep 17 00:00:00 2001 From: Vanessa Date: Tue, 4 Feb 2025 21:55:49 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/pull/14008 --- app/src/protyle/wysiwyg/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index 671e6478e..1931966ba 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -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 {