Skip to content

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

:bug: Restore slash hints after deleting unmatched text https://github.com/siyuan-note/siyuan/issues/18655

Danielfe2dd80404ae
diff --git a/app/src/protyle/hint/blockHintRange.test.ts b/app/src/protyle/hint/blockHintRange.test.ts
index a1cb5d62eb..2731782d33 100644
--- a/app/src/protyle/hint/blockHintRange.test.ts
+++ b/app/src/protyle/hint/blockHintRange.test.ts
@@ -1,6 +1,6 @@
import {describe, it} from "node:test";
import * as assert from "node:assert/strict";
-import {getBlockHintTriggerOffset, getBlockRefStaticText} from "./blockHintRange";
+import {endsWithMultiCharHintPrefix, getBlockHintTriggerOffset, getBlockRefStaticText} from "./blockHintRange";
describe("getBlockHintTriggerOffset", () => {
it("uses the latest overlapping trigger inside existing closing markers", () => {
@@ -63,3 +63,17 @@ describe("getBlockRefStaticText", () => {
assert.equal(getBlockRefStaticText("((query", "((", true), "query");
});
});
+
+describe("endsWithMultiCharHintPrefix", () => {
+ const hintKeys = ["((", "【【", "[[", "{{", "#", "/", "、", ":"];
+
+ it("ends the current hint when another multi-character hint starts", () => {
+ assert.equal(endsWithMultiCharHintPrefix("2【", hintKeys), true);
+ assert.equal(endsWithMultiCharHintPrefix("query[", hintKeys), true);
+ });
+
+ it("keeps the current hint active for ordinary query text", () => {
+ assert.equal(endsWithMultiCharHintPrefix("2级", hintKeys), false);
+ assert.equal(endsWithMultiCharHintPrefix("2", hintKeys), false);
+ });
+});
diff --git a/app/src/protyle/hint/blockHintRange.ts b/app/src/protyle/hint/blockHintRange.ts
index 0422ecfbdf..6a76a2c677 100644
--- a/app/src/protyle/hint/blockHintRange.ts
+++ b/app/src/protyle/hint/blockHintRange.ts
@@ -11,3 +11,7 @@ export const getBlockHintTriggerOffset = (textBeforeCaret: string, textAfterCare
export const getBlockRefStaticText = (selectedText: string, splitChar: string, includesTrigger: boolean) => {
return includesTrigger ? selectedText.substring(splitChar.length) : selectedText;
};
+
+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.ts
index d493bc1db8..b2c3160ce0 100644
--- a/app/src/protyle/hint/index.ts
+++ b/app/src/protyle/hint/index.ts
@@ -60,7 +60,7 @@ import {updateAttrViewCellAnimation} from "../render/av/action";
import {setFold} from "../util/blockFold";
import {getIconValueKind} from "../../emoji/iconValue";
import {getCreateTargetContext, isSameCreateTargetContext} from "./createTargetContext";
-import {getBlockHintTriggerOffset, getBlockRefStaticText} from "./blockHintRange";
+import {endsWithMultiCharHintPrefix, getBlockHintTriggerOffset, getBlockRefStaticText} from "./blockHintRange";
const genEmojiInsertHTML = (value: string) => {
const kind = getIconValueKind(value);
@@ -286,7 +286,9 @@ export class Hint {
if (this.enableSlash && !isMobile() && blockElement && !isInEmbedBlock(blockElement)) {
const slashData = hintSlash(key, protyle);
if (slashData.length === 0) {
- this.enableExtend = false;
+ if (endsWithMultiCharHintPrefix(key, protyle.options.hint.extend.map((item) => item.key))) {
+ this.enableExtend = false;
+ }
this.genHTML(slashData, protyle, true, "hint");
return;
}