Skip to content

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

:bug: Improve cursor restoration after undoing block creation while writing https://github.com/siyuan-note/siyuan/issues/18320

Daniel48e02fde4809
diff --git a/app/src/protyle/wysiwyg/enter.ts b/app/src/protyle/wysiwyg/enter.ts
index 042756b34a..42c03cf61e 100644
--- a/app/src/protyle/wysiwyg/enter.ts
+++ b/app/src/protyle/wysiwyg/enter.ts
@@ -1,5 +1,5 @@
import {genEmptyElement, genHeadingElement, insertEmptyBlock} from "../../block/util";
-import {focusByRange, focusByWbr, getSelectionOffset, setLastNodeRange} from "../util/selection";
+import {focusByRange, focusByWbr, getSelectionOffset, getUndoFocusContext, setLastNodeRange} from "../util/selection";
import {
getContenteditableElement, getParentBlock,
getEmbedChildOperationContext,
@@ -234,6 +234,7 @@ export const enter = async (blockElement: HTMLElement, range: Range, protyle: IP
removeEmptyNode(newElement);
return true;
}
+ const undoFocusContext = getUndoFocusContext(protyle.wysiwyg.element, range);
range.insertNode(document.createElement("wbr"));
const html = blockElement.outerHTML;
const parentHTML = getParentBlock(blockElement).outerHTML;
@@ -314,6 +315,7 @@ export const enter = async (blockElement: HTMLElement, range: Range, protyle: IP
action: "update",
data: html,
id,
+ context: undoFocusContext,
});
} else {
doOperation.push({