From 054263d8e9c229015a22efe1742bbd25b6fe2750 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 16 Oct 2024 23:48:43 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/12792 --- app/src/protyle/util/selection.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/protyle/util/selection.ts b/app/src/protyle/util/selection.ts index 2d7b9894903..926200eb904 100644 --- a/app/src/protyle/util/selection.ts +++ b/app/src/protyle/util/selection.ts @@ -314,6 +314,10 @@ export const setLastNodeRange = (editElement: Element, range: Range, setStart = // 防止单元格中 ⇧↓ 全部选中 return range; } + // https://github.com/siyuan-note/siyuan/issues/12792 + if (!lastNode.lastChild) { + break; + } // 最后一个为多种行内元素嵌套 lastNode = lastNode.lastChild as Element; } @@ -322,9 +326,17 @@ export const setLastNodeRange = (editElement: Element, range: Range, setStart = lastNode = editElement; } if (setStart) { - range.setStart(lastNode, lastNode.textContent.length); + if (lastNode.nodeType !== 3 && lastNode.classList.contains("render-node") && lastNode.innerHTML === "") { + range.setStartAfter(lastNode); + } else { + range.setStart(lastNode, lastNode.textContent.length); + } } else { - range.setEnd(lastNode, lastNode.textContent.length); + if (lastNode.nodeType !== 3 && lastNode.classList.contains("render-node") && lastNode.innerHTML === "") { + range.setStartAfter(lastNode); + } else { + range.setEnd(lastNode, lastNode.textContent.length); + } } return range; };