An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Restore caret after undoing agent skill insertion https://github.com/siyuan-note/siyuan/issues/18880
Danielc68d36998d7a
diff --git a/app/src/protyle/hint/blockHintRange.test.ts b/app/src/protyle/hint/blockHintRange.test.tsindex 0873104d8c..a48669bc2d 100644--- a/app/src/protyle/hint/blockHintRange.test.ts+++ b/app/src/protyle/hint/blockHintRange.test.ts@@ -4,6 +4,7 @@ import {endsWithMultiCharHintPrefix,getBlockHintTriggerOffset,getBlockRefStaticText,+ shouldCaptureHintUndoFocus,shouldIgnoreHintTrigger,} from "./blockHintRange";@@ -86,6 +87,24 @@ describe("shouldIgnoreHintTrigger", () => {});});+describe("shouldCaptureHintUndoFocus", () => {+ const blockHintKeys = ["((", "[[", "((", "【【"];++ it("captures block hint focus in all editors", () => {+ assert.equal(shouldCaptureHintUndoFocus("[[", blockHintKeys, false), true);+ });++ it("captures slash hint focus in lite editors", () => {+ assert.equal(shouldCaptureHintUndoFocus("/", blockHintKeys, true), true);+ assert.equal(shouldCaptureHintUndoFocus("、", blockHintKeys, true), true);+ });++ it("does not change regular editor slash hint focus handling", () => {+ assert.equal(shouldCaptureHintUndoFocus("/", blockHintKeys, false), false);+ assert.equal(shouldCaptureHintUndoFocus("#", blockHintKeys, true), false);+ });+});+describe("endsWithMultiCharHintPrefix", () => {const hintKeys = ["((", "【【", "[[", "{{", "#", "/", "、", ":"];diff --git a/app/src/protyle/hint/blockHintRange.ts b/app/src/protyle/hint/blockHintRange.tsindex bb691785fd..6f4903a882 100644--- a/app/src/protyle/hint/blockHintRange.ts+++ b/app/src/protyle/hint/blockHintRange.ts@@ -19,6 +19,10 @@ export const shouldIgnoreHintTrigger = (activeHint: string, candidateHint: strinreturn activeHint === "#" && ["/", "、"].includes(candidateHint);};+export const shouldCaptureHintUndoFocus = (splitChar: string, blockHintKeys: string[], lite: boolean) => {+ return blockHintKeys.includes(splitChar) || (lite && ["/", "、"].includes(splitChar));+};+export const endsWithMultiCharHintPrefix = (key: string, hintKeys: string[]) => {return hintKeys.some((hintKey) => hintKey.length > 1 && key.endsWith(hintKey.substring(0, 1)));};diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.tsindex 36e8a5f1e5..0ff1799aee 100644--- a/app/src/protyle/hint/index.ts+++ b/app/src/protyle/hint/index.ts@@ -64,6 +64,7 @@ import {endsWithMultiCharHintPrefix,getBlockHintTriggerOffset,getBlockRefStaticText,+ shouldCaptureHintUndoFocus,shouldIgnoreHintTrigger,} from "./blockHintRange";@@ -701,7 +702,7 @@ ${genHintItemHTML(item)}id = nodeElement.getAttribute("data-node-id");}const html = nodeElement.outerHTML;- const undoContext = Constants.BLOCK_HINT_KEYS.includes(this.splitChar) ?+ const undoContext = shouldCaptureHintUndoFocus(this.splitChar, Constants.BLOCK_HINT_KEYS, protyle.lite) ?getUndoFocusContext(protyle.wysiwyg.element, range, true) : undefined;// 自顶向下法新建文档后光标定位问题 https://github.com/siyuan-note/siyuan/issues/299if (this.lastIndex > -1) {@@ -786,7 +787,7 @@ ${genHintItemHTML(item)}return;} else if (this.splitChar === "/" || this.splitChar === "、") {if (protyle.lite) {- insertHTML(value, protyle);+ insertHTML(value, protyle, false, false, false, undefined, undoContext);} else if (value === "((" || value === "{{") {this.enableExtend = true;if (value === "((") {diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.tsindex b299ea7fa9..c0b3cc0834 100644--- a/app/src/protyle/util/insertHTML.ts+++ b/app/src/protyle/util/insertHTML.ts@@ -900,7 +900,8 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,// 在开头粘贴块则插入上方insertByCursor = false,// 根据块级拖拽指示线强制插入方向- insertPosition?: "before" | "after") => {+ insertPosition?: "before" | "after",+ undoContext?: Record<string, string>) => {if (html === "") {return;}@@ -1271,10 +1272,10 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,// 相邻标签之间插入空格区隔,避免后续 SpinBlockDOM 解析时合并为一个标签 https://github.com/siyuan-note/siyuan/issues/18191fixAdjacentTags(getContenteditableElement(blockElement));protyle.wysiwyg.lastHTMLs[id] = oldHTML;- input(protyle, blockElement as HTMLElement, range, true, undefined, isCrossBlockRange ? {+ input(protyle, blockElement as HTMLElement, range, true, undefined, isCrossBlockRange || undoContext ? {doOperations: crossBlockDoOperations,undoOperations: crossBlockUndoOperations,- undoContext: crossBlockUndoFocusContext,+ undoContext: crossBlockUndoFocusContext || undoContext,} : undefined);return;}