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: Align reference target removal controls https://github.com/siyuan-note/siyuan/issues/20907
Daniel331eb4a05321
diff --git a/app/src/protyle/render/av/collectionReference.test.ts b/app/src/protyle/render/av/collectionReference.test.tsindex 77cabcc90c..1b63db5acf 100644--- a/app/src/protyle/render/av/collectionReference.test.ts+++ b/app/src/protyle/render/av/collectionReference.test.ts@@ -48,7 +48,7 @@ const browserCases = async (sourceCode: string, languages: Record<string, string"../../../block/Panel": {BlockPanel: class {}},})[name] || {});const tick = () => new Promise(resolve => setTimeout(resolve, 0));- for (const width of [1000, 320]) {+ for (const [width, key] of [[1000, ""], [320, "Enter"], [320, " "]] as const) {const host = document.createElement("div");host.style.width = `${width}px`;document.body.append(host);@@ -82,7 +82,9 @@ const browserCases = async (sourceCode: string, languages: Record<string, stringcheck.equal(host.querySelector("[data-preview-reference]").children.length, 0);host.querySelector<HTMLButtonElement>("[data-reference]").click();const pending = inputOptions.onConfirm("20261026000000-pending", dialog);- host.querySelector<HTMLButtonElement>("[data-clear-reference]").click();+ const clear = host.querySelector<SVGSVGElement>("[data-clear-reference]");+ clear.dispatchEvent(key ? new KeyboardEvent("keydown", {key, bubbles: true, cancelable: true}) :+ new MouseEvent("click", {bubbles: true}));pendingSelection({code: 0});await pending;check.equal(source.referenceID, undefined);@@ -94,7 +96,7 @@ const browserCases = async (sourceCode: string, languages: Record<string, stringreturn "Reference collection DOM cases passed";};-test("reference selection, current document, clearing and stale labels work on desktop and narrow layouts", {+test("reference selection, current document, mouse and keyboard clearing, and stale labels work on desktop and narrow layouts", {skip: process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY,timeout: 45000,}, async () => {diff --git a/app/src/protyle/render/av/collectionReference.ts b/app/src/protyle/render/av/collectionReference.tsindex 274e75afc6..2b1dc7bd73 100644--- a/app/src/protyle/render/av/collectionReference.ts+++ b/app/src/protyle/render/av/collectionReference.ts@@ -19,7 +19,7 @@ export const mountCollectionReference = (host: HTMLElement, source: AVAutomationconst id = source.referenceID;host.className = "av__automation-control";host.innerHTML = `<span class="av__automation-control-label">${lang.automationCollectionReference}</span>-<div class="av__automation-row">${id ? `<button type="button" class="b3-button b3-button--cancel b3-button--wrap fn__flex-1 av__automation-source-action" data-preview-reference data-id="${escapeAttr(id)}">${escapeHtml(id)}</button><button type="button" class="block__icon" data-clear-reference aria-label="${escapeAttr(lang.delete)}"><svg><use xlink:href="#iconClose"></use></svg></button>` : ""}</div>+<div class="av__automation-row">${id ? `<button type="button" class="b3-button b3-button--cancel b3-button--wrap fn__flex-1 av__automation-source-action" data-preview-reference data-id="${escapeAttr(id)}">${escapeHtml(id)}</button><svg class="b3-menu__action b3-menu__action--show b3-menu__action--warning fn__pointer ariaLabel" data-clear-reference role="button" tabindex="0" data-position="north" aria-label="${escapeAttr(lang.delete)}"><use xlink:href="#iconClose"></use></svg>` : ""}</div><div class="av__automation-row"><button type="button" class="b3-button b3-button--cancel b3-button--wrap av__automation-source-action" data-reference>${lang.select}</button><button type="button" class="b3-button b3-button--cancel b3-button--wrap av__automation-source-action" data-reference-document>${lang.filterCurrentDocument}</button></div><div class="ft__on-surface ft__smaller av__automation-tip">${lang.automationCollectionReferenceTip}</div>`;resize();@@ -41,14 +41,14 @@ export const mountCollectionReference = (host: HTMLElement, source: AVAutomationreturn true;};host.addEventListener("click", event => {- const target = (event.target as Element).closest<HTMLElement>("button");+ const target = (event.target as Element).closest("button, [data-clear-reference]");if (!target) { return; }if (target.hasAttribute("data-clear-reference")) {selectionRevision++;delete source.referenceID;save();void render();- } else if (target.hasAttribute("data-preview-reference")) {+ } else if (target instanceof HTMLButtonElement && target.hasAttribute("data-preview-reference")) {window.siyuan.blockPanels.push(new BlockPanel({app: protyle.app, targetElement: target,isBacklink: false, refDefs: [{refID: source.referenceID}]}));} else if (target.hasAttribute("data-reference-document")) {@@ -69,5 +69,12 @@ export const mountCollectionReference = (host: HTMLElement, source: AVAutomation}});}});+ host.addEventListener("keydown", event => {+ const target = (event.target as Element).closest("[data-clear-reference]");+ if (!target || event.isComposing || event.repeat || !["Enter", " "].includes(event.key)) { return; }+ event.preventDefault();+ event.stopPropagation();+ target.dispatchEvent(new MouseEvent("click", {bubbles: true}));+ });void render();};