Skip to content

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

:art: https://github.com/siyuan-note/siyuan/issues/13776

Vanessae8a186092013
diff --git a/app/src/block/Panel.ts b/app/src/block/Panel.ts
index 05bd50f393..2785349e92 100644
--- a/app/src/block/Panel.ts
+++ b/app/src/block/Panel.ts
@@ -29,6 +29,7 @@ export class BlockPanel {
public editors: Protyle[] = [];
private observerResize: ResizeObserver;
private observerLoad: IntersectionObserver;
+ private originalRefBlockIDs: IObject;
// x,y 和 targetElement 二选一必传
constructor(options: {
@@ -38,7 +39,8 @@ export class BlockPanel {
defIds?: string[],
isBacklink: boolean,
x?: number,
- y?: number
+ y?: number,
+ originalRefBlockIDs?: IObject, // isBacklink 为 true 时有效
}) {
this.id = genUUID();
this.targetElement = options.targetElement;
@@ -48,6 +50,7 @@ export class BlockPanel {
this.x = options.x;
this.y = options.y;
this.isBacklink = options.isBacklink;
+ this.originalRefBlockIDs = options.originalRefBlockIDs;
this.element = document.createElement("div");
this.element.classList.add("block__popover");
@@ -169,6 +172,7 @@ export class BlockPanel {
const editor = new Protyle(this.app, editorElement, {
blockId: this.nodeIds[index],
defId: this.defIds[index] || this.defIds[0] || "",
+ originalRefBlockIDs: this.isBacklink ? this.originalRefBlockIDs : undefined,
action,
render: {
scroll: true,
diff --git a/app/src/block/popover.ts b/app/src/block/popover.ts
index 87f33bae66..60e2a5f2a5 100644
--- a/app/src/block/popover.ts
+++ b/app/src/block/popover.ts
@@ -336,6 +336,7 @@ export const showPopover = async (app: App, showRef = false) => {
}
let ids: string[];
let defIds: string[];
+ let originalRefBlockIDs: IObject
const dataId = popoverTargetElement.getAttribute("data-id");
if (dataId) {
// backlink/util/hint/正文标题 上的弹层
@@ -343,6 +344,7 @@ export const showPopover = async (app: App, showRef = false) => {
const postResponse = await fetchSyncPost("/api/block/getRefIDs", {id: dataId});
ids = postResponse.data.refIDs;
defIds = postResponse.data.defIDs;
+ originalRefBlockIDs = postResponse.data.originalRefBlockIDs;
} else {
if (dataId.startsWith("[")) {
ids = JSON.parse(dataId);
@@ -394,6 +396,7 @@ export const showPopover = async (app: App, showRef = false) => {
const postResponse = await fetchSyncPost(url, {id: targetId});
ids = postResponse.data.refIDs;
defIds = postResponse.data.defIDs;
+ originalRefBlockIDs = postResponse.data.originalRefBlockIDs;
}
}
@@ -414,6 +417,7 @@ export const showPopover = async (app: App, showRef = false) => {
isBacklink: showRef || popoverTargetElement.classList.contains("protyle-attr--refcount") || popoverTargetElement.classList.contains("counter"),
nodeIds: ids,
defIds,
+ originalRefBlockIDs,
}));
}
// 不能清除,否则ctrl 后 shift 就 无效 popoverTargetElement = undefined;
diff --git a/app/src/plugin/index.ts b/app/src/plugin/index.ts
index fbe0440a9e..230082eb29 100644
--- a/app/src/plugin/index.ts
+++ b/app/src/plugin/index.ts
@@ -385,6 +385,7 @@ export class Plugin {
y?: number,
targetElement?: HTMLElement,
isBacklink: boolean,
+ originalRefBlockIDs?: IObject,
}) => {
window.siyuan.blockPanels.push(new BlockPanel({
app: this.app,
diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.ts
index ca106b10b6..353cd32eb7 100644
--- a/app/src/protyle/index.ts
+++ b/app/src/protyle/index.ts
@@ -290,6 +290,7 @@ export class Protyle {
fetchPost("/api/filetree/getDoc", {
id: mergedOptions.blockId,
isBacklink: mergedOptions.action.includes(Constants.CB_GET_BACKLINK),
+ originalRefBlockIDs: mergedOptions.originalRefBlockIDs,
// 0: 仅当前 ID(默认值),1:向上 2:向下,3:上下都加载,4:加载最后
mode: (mergedOptions.action && mergedOptions.action.includes(Constants.CB_GET_CONTEXT)) ? 3 : 0,
size: mergedOptions.action?.includes(Constants.CB_GET_ALL) ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks,
diff --git a/app/src/types/protyle.d.ts b/app/src/types/protyle.d.ts
index 1cfd4f2377..f29c9f20cd 100644
--- a/app/src/types/protyle.d.ts
+++ b/app/src/types/protyle.d.ts
@@ -446,6 +446,7 @@ interface IProtyleOptions {
mode?: TEditorMode,
blockId?: string
rootId?: string
+ originalRefBlockIDs?: IObject
key?: string
defId?: string
render?: {