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: Exclude manually typed closing brackets from block reference search https://github.com/siyuan-note/siyuan/issues/20522
Nathan K9787fa7a70c2
diff --git a/app/src/protyle/hint/blockHintRange.test.ts b/app/src/protyle/hint/blockHintRange.test.tsindex b62781ca1c..99de06bf9b 100644--- a/app/src/protyle/hint/blockHintRange.test.ts+++ b/app/src/protyle/hint/blockHintRange.test.ts@@ -7,6 +7,7 @@ import {isBlockHintQueryAtCaret,shouldCaptureHintUndoFocus,shouldIgnoreHintTrigger,+ stripBlockHintCloseKey,} from "./blockHintRange";describe("getBlockHintTriggerOffset", () => {@@ -86,6 +87,23 @@ describe("getBlockRefStaticText", () => {assert.equal(getBlockRefStaticText("[[旧的开始", "[[", true), "旧的开始");assert.equal(getBlockRefStaticText("((query", "((", true), "query");});++ it("removes a manually typed closing marker from an inline block hint", () => {+ assert.equal(getBlockRefStaticText("[[Title]]", "[[", true, "]]"), "Title");+ assert.equal(getBlockRefStaticText("【【标题】】", "【【", true, "】】"), "标题");+ assert.equal(getBlockRefStaticText("[[Title]]", "[[", false, "]]"), "[[Title]]");+ });+});++describe("stripBlockHintCloseKey", () => {+ it("removes only a complete trailing closing marker", () => {+ assert.equal(stripBlockHintCloseKey("Title]]", "]]"), "Title");+ assert.equal(stripBlockHintCloseKey("query))", "))"), "query");+ assert.equal(stripBlockHintCloseKey("Title]", "]]"), "Title]");+ assert.equal(stripBlockHintCloseKey("[draft] notes", "]]"), "[draft] notes");+ assert.equal(stripBlockHintCloseKey("]]", "]]"), "");+ assert.equal(stripBlockHintCloseKey("Title]]", undefined), "Title]]");+ });});describe("shouldIgnoreHintTrigger", () => {diff --git a/app/src/protyle/hint/blockHintRange.ts b/app/src/protyle/hint/blockHintRange.tsindex 8e29d715ba..c4f476b575 100644--- a/app/src/protyle/hint/blockHintRange.ts+++ b/app/src/protyle/hint/blockHintRange.ts@@ -18,8 +18,14 @@ export const isBlockHintQueryAtCaret = (textBeforeCaret: string, textAfterCaret:return query.trimStart() === query && query.length < maxLength;};-export const getBlockRefStaticText = (selectedText: string, splitChar: string, includesTrigger: boolean) => {- return includesTrigger ? selectedText.substring(splitChar.length) : selectedText;+// 手动输入的闭合标记(如 [[标题]] 中的 ]])不属于查询内容,选中候选项时随触发符一起被替换+export const stripBlockHintCloseKey = (query: string, endSplit: string) => {+ return endSplit && query.endsWith(endSplit) ? query.substring(0, query.length - endSplit.length) : query;+};++export const getBlockRefStaticText = (selectedText: string, splitChar: string, includesTrigger: boolean,+ endSplit = "") => {+ return includesTrigger ? stripBlockHintCloseKey(selectedText.substring(splitChar.length), endSplit) : selectedText;};export const shouldIgnoreHintTrigger = (activeHint: string, candidateHint: string, blockHintKeys: string[]) => {diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.tsindex 48558602d7..93975a4162 100644--- a/app/src/protyle/hint/index.ts+++ b/app/src/protyle/hint/index.ts@@ -85,6 +85,7 @@ import {isBlockHintQueryAtCaret,shouldCaptureHintUndoFocus,shouldIgnoreHintTrigger,+ stripBlockHintCloseKey,} from "./blockHintRange";import {getMobileHintPosition} from "./mobileHintPosition";import {getLiteSlashMenuHTML} from "../../mobile/util/liteSlashMenu";@@ -1016,7 +1017,8 @@ ${genHintItemHTML(item)}tempElement = tempElement.firstElementChild as HTMLDivElement;if (refIsS) {const selectedText = stripSemanticMarkersFromRangeText(range).split(Constants.ZWSP).join("");- const staticText = getBlockRefStaticText(selectedText, this.splitChar, this.lastIndex > -1);+ const staticText = getBlockRefStaticText(selectedText, this.splitChar, this.lastIndex > -1,+ Constants.BLOCK_HINT_CLOSE_KEYS[this.splitChar]);if (staticText) {tempElement.setAttribute("data-subtype", "s");tempElement.innerText = staticText;@@ -1537,6 +1539,9 @@ ${genHintItemHTML(item)}if (this.splitChar === "【【" && currentLineValue.endsWith("【【】")) {return "";}+ if (Constants.BLOCK_HINT_KEYS.includes(this.splitChar)) {+ return stripBlockHintCloseKey(lastItem, Constants.BLOCK_HINT_CLOSE_KEYS[this.splitChar]);+ }return lastItem;}return undefined;