From bcb1bcc29089d73fce72e4886f1a18686443bc21 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Fri, 7 Jun 2024 00:17:54 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/11606 --- app/src/protyle/util/selection.ts | 8 +++++++- app/src/protyle/wysiwyg/remove.ts | 16 +++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/src/protyle/util/selection.ts b/app/src/protyle/util/selection.ts index a9410f299..b9518a046 100644 --- a/app/src/protyle/util/selection.ts +++ b/app/src/protyle/util/selection.ts @@ -486,10 +486,11 @@ export const focusByRange = (range: Range) => { selection.addRange(range); }; -export const focusBlock = (element: Element, parentElement?: HTMLElement, toStart = true) => { +export const focusBlock = (element: Element, parentElement?: HTMLElement, toStart = true): false | Range => { if (!element) { return false; } + // hr、嵌入块、数学公式、iframe、音频、视频、图表渲染块等,删除段落块后,光标位置矫正 https://github.com/siyuan-note/siyuan/issues/4143 if (element.classList.contains("render-node") || element.classList.contains("iframe") || element.classList.contains("hr") || element.classList.contains("av")) { const range = document.createRange(); @@ -609,6 +610,11 @@ export const focusBlock = (element: Element, parentElement?: HTMLElement, toStar return range; } else if (parentElement) { parentElement.focus(); + } else { + // li 下面为 hr、嵌入块、数学公式、iframe、音频、视频、图表渲染块等时递归处理 + if (element.classList.contains("li")) { + return focusBlock(element.querySelector('[data-node-id]'), parentElement, toStart); + } } return false; }; diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.ts index 675d8fe0b..86b94464e 100644 --- a/app/src/protyle/wysiwyg/remove.ts +++ b/app/src/protyle/wysiwyg/remove.ts @@ -197,13 +197,7 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran removeBlock(protyle, blockElement, range, type); return; } - // 设置 bq 和代码块光标 - if (["NodeCodeBlock", "NodeTable", "NodeAttributeView"].includes(blockType)) { - if (blockElement.previousElementSibling) { - focusBlock(blockElement.previousElementSibling, undefined, false); - } - return; - } + if (!blockElement.previousElementSibling && blockElement.parentElement.getAttribute("data-type") === "NodeBlockquote") { range.insertNode(document.createElement("wbr")); const blockParentElement = blockElement.parentElement; @@ -249,6 +243,14 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran removeLi(protyle, blockElement, range, type === "Delete"); return; } + // 设置 bq 和代码块光标 + // 需放在列表处理后 https://github.com/siyuan-note/siyuan/issues/11606 + if (["NodeCodeBlock", "NodeTable", "NodeAttributeView"].includes(blockType)) { + if (blockElement.previousElementSibling) { + focusBlock(blockElement.previousElementSibling, undefined, false); + } + return; + } if (blockType === "NodeHeading") { turnsIntoTransaction({ protyle: protyle,