Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Handle arrow navigation through empty paragraphs https://github.com/siyuan-note/siyuan/issues/18862

Daniela080a1181538
diff --git a/app/src/protyle/wysiwyg/input.ts b/app/src/protyle/wysiwyg/input.ts
index 2b33c73149..ea1fa3f874 100644
--- a/app/src/protyle/wysiwyg/input.ts
+++ b/app/src/protyle/wysiwyg/input.ts
@@ -365,15 +365,6 @@ export const input = async (protyle: IProtyle, blockElement: HTMLElement, range:
tempElement.innerHTML = html;
}
}
- const tempEditElement = getContenteditableElement(tempElement.content.firstElementChild);
- // 全选删除会一并移除零宽空格,补回后光标才能通过上下键进入空段落。
- // https://github.com/siyuan-note/siyuan/issues/18862
- if (tempElement.content.childElementCount === 1 &&
- tempElement.content.firstElementChild.getAttribute("data-type") === "NodeParagraph" &&
- tempEditElement?.innerHTML === "<wbr>") {
- tempEditElement.insertAdjacentText("afterbegin", Constants.ZWSP);
- html = tempElement.innerHTML;
- }
if (needRender && (
getContenteditableElement(tempElement.content.firstElementChild)?.innerHTML !== getContenteditableElement(blockElement).innerHTML ||
// 内容删空后使用上下键,光标无法到达 https://github.com/siyuan-note/siyuan/issues/4167 https://ld246.com/article/1636256333803
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index 8dd4c1b91f..b17f88688b 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -838,6 +838,14 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
(toNext ? getNextBlock(nodeElement) : undefined);
if (adjacentElement) {
adjacentElement = toPrevious ? getLastBlock(adjacentElement) : getFirstBlock(adjacentElement);
+ // 显式聚焦空段落,避免浏览器跨越容器边界时跳过该块。
+ // https://github.com/siyuan-note/siyuan/issues/18862
+ if ((event.key === "ArrowUp" || event.key === "ArrowDown") && isEmptyParagraph(adjacentElement)) {
+ focusBlock(adjacentElement, undefined, event.key === "ArrowDown");
+ event.stopPropagation();
+ event.preventDefault();
+ return;
+ }
if (adjacentElement.classList.contains("av") &&
focusAVByArrow(protyle, adjacentElement as HTMLElement, event.key)) {
event.stopPropagation();