From 22e954c4e785558dc9dc5754f12cc99e8d5a24af Mon Sep 17 00:00:00 2001 From: Vanessa Date: Mon, 21 Oct 2024 23:18:45 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/12868 --- app/src/protyle/wysiwyg/keydown.ts | 6 ++++-- app/src/protyle/wysiwyg/remove.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index ba9f85a33..3740c1b63 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -696,7 +696,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { // 页面按向下/右箭头丢失焦点 https://ld246.com/article/1629954026096 const lastEditElement = getContenteditableElement(nodeElement); // 代码块需替换最后一个 /n https://github.com/siyuan-note/siyuan/issues/3221 - if (lastEditElement && lastEditElement.textContent.replace(/\n$/, "").length <= getSelectionOffset(lastEditElement, undefined, range).end) { + if (lastEditElement && !lastEditElement.querySelector(".emoji") && lastEditElement.textContent.replace(/\n$/, "").length <= getSelectionOffset(lastEditElement, undefined, range).end) { event.stopPropagation(); event.preventDefault(); focusByRange(range); @@ -860,7 +860,9 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { const currentNode = range.startContainer.childNodes[range.startOffset - 1] as HTMLElement; if (position.start === 0 && ( range.startOffset === 0 || - (currentNode && currentNode.nodeType === 3 && !hasPreviousSibling(currentNode) && currentNode.innerText === "") // https://ld246.com/article/1649251218696 + (currentNode && currentNode.nodeType === 3 && !hasPreviousSibling(currentNode) && + // 需使用 textContent,文本元素没有 innerText + currentNode.textContent === "") // https://ld246.com/article/1649251218696 )) { removeBlock(protyle, nodeElement, range, "Backspace"); event.stopPropagation(); diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.ts index 1869605f1..e50e8a4c6 100644 --- a/app/src/protyle/wysiwyg/remove.ts +++ b/app/src/protyle/wysiwyg/remove.ts @@ -389,7 +389,7 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran focusBlock(previousLastElement, undefined, false); } else { const previousLastEditElement = getContenteditableElement(previousLastElement); - if (editableElement && editableElement.textContent !== "") { + if (editableElement && (editableElement.textContent !== "" || editableElement.querySelector(".emoji"))) { // 非空块 range.setEndAfter(editableElement.lastChild); // 数学公式回车后再删除 https://github.com/siyuan-note/siyuan/issues/3850