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: Preserve block reference hints before ideographic comma https://github.com/siyuan-note/siyuan/issues/18802
Danielb2fd99794952
diff --git a/app/src/protyle/hint/blockHintRange.test.ts b/app/src/protyle/hint/blockHintRange.test.tsindex 2731782d33..0873104d8c 100644--- a/app/src/protyle/hint/blockHintRange.test.ts+++ b/app/src/protyle/hint/blockHintRange.test.ts@@ -1,6 +1,11 @@import {describe, it} from "node:test";import * as assert from "node:assert/strict";-import {endsWithMultiCharHintPrefix, getBlockHintTriggerOffset, getBlockRefStaticText} from "./blockHintRange";+import {+ endsWithMultiCharHintPrefix,+ getBlockHintTriggerOffset,+ getBlockRefStaticText,+ shouldIgnoreHintTrigger,+} from "./blockHintRange";describe("getBlockHintTriggerOffset", () => {it("uses the latest overlapping trigger inside existing closing markers", () => {@@ -64,6 +69,23 @@ describe("getBlockRefStaticText", () => {});});+describe("shouldIgnoreHintTrigger", () => {+ const blockHintKeys = ["((", "[[", "((", "【【"];++ it("keeps block reference queries intact when slash hints appear inside them", () => {+ assert.equal(shouldIgnoreHintTrigger("[[", "、", blockHintKeys), true);+ assert.equal(shouldIgnoreHintTrigger("((", "/", blockHintKeys), true);+ assert.equal(shouldIgnoreHintTrigger("[[", "#", blockHintKeys), true);+ assert.equal(shouldIgnoreHintTrigger("[[", ":", blockHintKeys), true);+ });++ it("does not block unrelated hint contexts", () => {+ assert.equal(shouldIgnoreHintTrigger("", "、", blockHintKeys), false);+ assert.equal(shouldIgnoreHintTrigger("#", "、", blockHintKeys), true);+ assert.equal(shouldIgnoreHintTrigger("、", "[[", blockHintKeys), false);+ });+});+describe("endsWithMultiCharHintPrefix", () => {const hintKeys = ["((", "【【", "[[", "{{", "#", "/", "、", ":"];diff --git a/app/src/protyle/hint/blockHintRange.ts b/app/src/protyle/hint/blockHintRange.tsindex 6a76a2c677..bb691785fd 100644--- a/app/src/protyle/hint/blockHintRange.ts+++ b/app/src/protyle/hint/blockHintRange.ts@@ -12,6 +12,13 @@ export const getBlockRefStaticText = (selectedText: string, splitChar: string, ireturn includesTrigger ? selectedText.substring(splitChar.length) : selectedText;};+export const shouldIgnoreHintTrigger = (activeHint: string, candidateHint: string, blockHintKeys: string[]) => {+ if (blockHintKeys.includes(activeHint) && [":", "#", "/", "、"].includes(candidateHint)) {+ return true;+ }+ return activeHint === "#" && ["/", "、"].includes(candidateHint);+};+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 b1a0f437ef..308eed3af2 100644--- a/app/src/protyle/hint/index.ts+++ b/app/src/protyle/hint/index.ts@@ -60,7 +60,12 @@ import {updateAttrViewCellAnimation} from "../render/av/action";import {setFold} from "../util/blockFold";import {getIconValueKind} from "../../emoji/iconValue";import {getCreateTargetContext, isSameCreateTargetContext} from "./createTargetContext";-import {endsWithMultiCharHintPrefix, getBlockHintTriggerOffset, getBlockRefStaticText} from "./blockHintRange";+import {+ endsWithMultiCharHintPrefix,+ getBlockHintTriggerOffset,+ getBlockRefStaticText,+ shouldIgnoreHintTrigger,+} from "./blockHintRange";const genEmojiInsertHTML = (value: string) => {const kind = getIconValueKind(value);@@ -1189,8 +1194,10 @@ ${genHintItemHTML(item)}Constants.BLOCK_HINT_CLOSE_KEYS[item.key]);}if (this.lastIndex < currentLastIndex) {- this.splitChar = item.key;- this.lastIndex = currentLastIndex;+ if (!shouldIgnoreHintTrigger(this.splitChar, item.key, Constants.BLOCK_HINT_KEYS)) {+ this.splitChar = item.key;+ this.lastIndex = currentLastIndex;+ }}});if (this.lastIndex === -1) {