Skip to content

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

:bug: Preserve database binding targets during path selection https://github.com/siyuan-note/siyuan/issues/19958

Danielebc34b33073a
diff --git a/app/src/protyle/render/av/batchEdit.ts b/app/src/protyle/render/av/batchEdit.ts
index 7883693253..033c0a4919 100644
--- a/app/src/protyle/render/av/batchEdit.ts
+++ b/app/src/protyle/render/av/batchEdit.ts
@@ -263,10 +263,10 @@ export const openAVFieldBinding = (options: {
context.destroy();
return;
}
- // 隐藏主键或虚拟滚动条目使用现有字段代理,候选关闭后及时清理。
+ // 候选关闭后仍可能继续选址新建,保留代理直到条目重绘或绑定目标改变。
const hint = options.protyle.hint.element;
const observer = new MutationObserver(() => {
- if (!field.isConnected || hint.classList.contains("fn__none") ||
+ if (!field.isConnected ||
options.protyle.toolbar.range?.startContainer !== field) {
observer.disconnect();
context.destroy();
diff --git a/app/src/protyle/render/av/fieldBinding.test.ts b/app/src/protyle/render/av/fieldBinding.test.ts
index 9a87eb1a0f..052878ea84 100644
--- a/app/src/protyle/render/av/fieldBinding.test.ts
+++ b/app/src/protyle/render/av/fieldBinding.test.ts
@@ -5,13 +5,13 @@ import {test} from "node:test";
import {runInNewContext} from "node:vm";
import {ScriptTarget, transpileModule} from "typescript";
-test("hidden primary binding reuses the field proxy and releases it when dismissed or unavailable", () => {
+test("hidden primary binding survives path selection and releases removed or replaced targets", () => {
const source = readFileSync(join(__dirname, "batchEdit.ts"), "utf8");
const code = transpileModule(source.substring(source.indexOf("export const openAVFieldBinding"))
.replace("export const", "const") + "\nopenAVFieldBinding;", {
compilerOptions: {target: ScriptTarget.ES2020},
}).outputText;
- for (const reason of ["dismissed", "removed", "replaced", "readonly"]) {
+ for (const reason of ["path-selection", "removed", "replaced", "readonly"]) {
let hidden = false;
let destroyed = 0;
let disconnected = 0;
@@ -39,8 +39,15 @@ test("hidden primary binding reuses the field proxy and releases it when dismiss
} else {
callback();
assert.equal(destroyed, 0);
- hidden = reason === "dismissed";
- field.isConnected = reason !== "removed";
+ if (reason === "path-selection") {
+ hidden = true;
+ callback();
+ assert.equal(destroyed, 0);
+ field.isConnected = false;
+ }
+ if (reason === "removed") {
+ field.isConnected = false;
+ }
if (reason === "replaced") {
protyle.toolbar.range.startContainer = {};
}