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: Honor dynamic loading in document backlink popovers https://github.com/siyuan-note/siyuan/issues/18652
Daniel226a9608173a
diff --git a/app/src/block/Panel.ts b/app/src/block/Panel.tsindex 06158d3354..c5530beecf 100644--- a/app/src/block/Panel.ts+++ b/app/src/block/Panel.ts@@ -25,6 +25,7 @@ import {matchesBlockPanelRemoval,planBlockPanelRemoval} from "./panelRemoval";+import {getBlockPanelLoadPlan} from "./panelLoad";const BLOCK_PANEL_EDITOR_MIN_HEIGHT = 155;@@ -408,31 +409,31 @@ export class BlockPanel {notebookId: response.data.box,rootID: response.data.rootID,});+ const loadPlan = getBlockPanelLoadPlan(response.data.rootID, refDef.refID, this.isBacklink);const action: TProtyleAction[] = [];- if (response.data.rootID !== refDef.refID) {+ if (!loadPlan.isDocument) {action.push(Constants.CB_GET_ALL);} else {action.push(Constants.CB_GET_CONTEXT);// 不需要高亮 https://github.com/siyuan-note/siyuan/issues/11160#issuecomment-2084652764}- if (this.isBacklink) {+ if (loadPlan.useBacklinkContext) {action.push(Constants.CB_GET_BACKLINK);}- const isDocument = response.data.rootID === refDef.refID;let isInitialRender = true;const editor = new Protyle(this.app, editorElement, {databaseAttr: true,blockId: refDef.refID,defIds: refDef.defIDs || [],- originalRefBlockIDs: this.isBacklink ? this.originalRefBlockIDs : undefined,+ originalRefBlockIDs: loadPlan.useBacklinkContext ? this.originalRefBlockIDs : undefined,action,render: {scroll: true,gutter: true,breadcrumbDocName: true,- background: isDocument,- title: isDocument, // 如果块是文档,显示文档标题+ background: loadPlan.isDocument,+ title: loadPlan.isDocument, // 如果块是文档,显示文档标题},typewriterMode: false,after: (editor) => {@@ -457,7 +458,7 @@ export class BlockPanel {}if (isInitialRender) {isInitialRender = false;- if (isDocument) {+ if (loadPlan.isDocument) {const contentElement = editor.protyle.contentElement;const titleElement = editor.protyle.title.element;const marginTop = parseFloat(getComputedStyle(titleElement).marginTop) || 0;diff --git a/app/src/block/panelLoad.test.ts b/app/src/block/panelLoad.test.tsnew file mode 100644index 0000000000..fe987d3264--- /dev/null+++ b/app/src/block/panelLoad.test.ts@@ -0,0 +1,33 @@+import {describe, it} from "node:test";+import * as assert from "node:assert/strict";+import {getBlockPanelLoadPlan} from "./panelLoad";++describe("getBlockPanelLoadPlan", () => {+ it("loads document backlinks as regular document context", () => {+ assert.deepEqual(getBlockPanelLoadPlan("document", "document", true), {+ isDocument: true,+ useBacklinkContext: false,+ });+ });++ it("keeps backlink context for blocks inside documents", () => {+ assert.deepEqual(getBlockPanelLoadPlan("document", "block", true), {+ isDocument: false,+ useBacklinkContext: true,+ });+ });++ it("loads regular document popovers without backlink context", () => {+ assert.deepEqual(getBlockPanelLoadPlan("document", "document", false), {+ isDocument: true,+ useBacklinkContext: false,+ });+ });++ it("loads regular block popovers without backlink context", () => {+ assert.deepEqual(getBlockPanelLoadPlan("document", "block", false), {+ isDocument: false,+ useBacklinkContext: false,+ });+ });+});diff --git a/app/src/block/panelLoad.ts b/app/src/block/panelLoad.tsnew file mode 100644index 0000000000..2164cabac8--- /dev/null+++ b/app/src/block/panelLoad.ts@@ -0,0 +1,12 @@+export interface IBlockPanelLoadPlan {+ isDocument: boolean;+ useBacklinkContext: boolean;+}++export const getBlockPanelLoadPlan = (rootID: string, refID: string, isBacklink: boolean): IBlockPanelLoadPlan => {+ const isDocument = rootID === refID;+ return {+ isDocument,+ useBacklinkContext: isBacklink && !isDocument,+ };+};