Skip to content

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

:bug: Preserve caret navigation after clearing paragraph content https://github.com/siyuan-note/siyuan/issues/18862

Daniel9fb098583575
diff --git a/app/src/protyle/wysiwyg/input.ts b/app/src/protyle/wysiwyg/input.ts
index ea1fa3f874..2b33c73149 100644
--- a/app/src/protyle/wysiwyg/input.ts
+++ b/app/src/protyle/wysiwyg/input.ts
@@ -365,6 +365,15 @@ 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