Skip to content

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

:bug: Preserve all characters outside block reference triggers https://github.com/siyuan-note/siyuan/issues/18626

Danielacd6a417866a
diff --git a/app/src/protyle/hint/blockHintRange.test.ts b/app/src/protyle/hint/blockHintRange.test.ts
index ff11154bbe..72e5633750 100644
--- a/app/src/protyle/hint/blockHintRange.test.ts
+++ b/app/src/protyle/hint/blockHintRange.test.ts
@@ -3,7 +3,7 @@ import * as assert from "node:assert/strict";
import {getBlockHintCloseLength} from "./blockHintRange";
describe("getBlockHintCloseLength", () => {
- it("keeps the outer closing bracket when creating a reference inside nested brackets", () => {
+ it("preserves brackets outside the trigger range", () => {
const text = "[[[]]";
const triggerOffset = 1;
const caretOffset = 3;
@@ -11,7 +11,7 @@ describe("getBlockHintCloseLength", () => {
text.substring(caretOffset), "[[", "]]");
assert.equal(text.substring(0, triggerOffset) + "reference" +
- text.substring(caretOffset + closeLength), "[reference]");
+ text.substring(caretOffset + closeLength), "[reference]]");
});
it("removes an automatically completed closing marker", () => {
@@ -19,10 +19,10 @@ describe("getBlockHintCloseLength", () => {
assert.equal(getBlockHintCloseLength("text", "))tail", "((", "))"), 2);
});
- it("preserves closing markers belonging to outer pairs", () => {
- assert.equal(getBlockHintCloseLength("[", "]]", "[[", "]]"), 1);
- assert.equal(getBlockHintCloseLength("[[", "]]]", "[[", "]]"), 1);
- assert.equal(getBlockHintCloseLength("【", "】】", "【【", "】】"), 1);
+ it("does not remove closing markers after an unmatched opening marker", () => {
+ assert.equal(getBlockHintCloseLength("[", "]]", "[[", "]]"), 0);
+ assert.equal(getBlockHintCloseLength("[[", "]]]", "[[", "]]"), 0);
+ assert.equal(getBlockHintCloseLength("【", "】】", "【【", "】】"), 0);
});
it("does not remove unrelated closing markers", () => {
diff --git a/app/src/protyle/hint/blockHintRange.ts b/app/src/protyle/hint/blockHintRange.ts
index d2efd16932..e177f05a02 100644
--- a/app/src/protyle/hint/blockHintRange.ts
+++ b/app/src/protyle/hint/blockHintRange.ts
@@ -16,9 +16,5 @@ export const getBlockHintCloseLength = (textBeforeTrigger: string, textAfterCare
}
}
- let closeRunLength = 0;
- while (textAfterCaret.substring(closeRunLength, closeRunLength + 1) === closeChar) {
- closeRunLength++;
- }
- return Math.min(endSplit.length, Math.max(0, closeRunLength - unmatchedOpenCount));
+ return unmatchedOpenCount === 0 ? endSplit.length : 0;
};
diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.ts
index ceaf634eda..b2ed957dbf 100644
--- a/app/src/protyle/hint/index.ts
+++ b/app/src/protyle/hint/index.ts
@@ -660,7 +660,7 @@ ${genHintItemHTML(item)}
// QQ 拼音输入法自动补全需移除补全内容 https://github.com/siyuan-note/siyuan/issues/320
// 前后有标记符的情况 https://github.com/siyuan-note/siyuan/issues/2511
const endSplit = Constants.BLOCK_HINT_CLOSE_KEYS[this.splitChar];
- // 仅移除当前提示所属的闭合符号,保留外层配对和后续文本中的同名符号
+ // 仅移除当前提示所属的闭合符号,保留触发范围外的原有符号
if (Constants.BLOCK_HINT_KEYS.includes(this.splitChar) && endSplit && this.lastIndex > -1 &&
range.startContainer.nodeType === 3) {
const textNode = range.startContainer as Text;