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/pull/16727

Vanessad5d10dd41b0c
diff --git a/app/src/layout/tabUtil.ts b/app/src/layout/tabUtil.ts
index 0fa76c7b74..221b247d3b 100644
--- a/app/src/layout/tabUtil.ts
+++ b/app/src/layout/tabUtil.ts
@@ -360,15 +360,32 @@ export const copyTab = (app: App, tab: Tab) => {
});
};
+const getRootID = (item: Tab) => {
+ if (item.model instanceof Editor) {
+ return item.model.editor.protyle.block.rootID;
+ } else if (!item.model) {
+ const initTab = item.headElement.getAttribute("data-initdata");
+ if (initTab) {
+ try {
+ const initTabData = JSON.parse(initTab);
+ if (initTabData && initTabData.instance === "Editor" && initTabData.rootId) {
+ return initTabData.rootId;
+ }
+ } catch (e) {
+ console.warn("Failed to parse tab init data:", e);
+ }
+ }
+ }
+};
+
+
export const closeTabByType = (tab: Tab, type: "closeOthers" | "closeAll" | "other", tabs?: Tab[]) => {
const rootIDs: string[] = [];
if (type === "closeOthers") {
for (let index = 0; index < tab.parent.children.length; index++) {
const item = tab.parent.children[index];
if (item.id !== tab.id && !item.headElement.classList.contains("item--pin")) {
- if (item.model instanceof Editor) {
- rootIDs.push(item.model.editor.protyle.block.rootID);
- }
+ rootIDs.push(getRootID(item));
item.parent.removeTab(item.id, true, false);
index--;
}
@@ -377,9 +394,7 @@ export const closeTabByType = (tab: Tab, type: "closeOthers" | "closeAll" | "oth
for (let index = 0; index < tab.parent.children.length; index++) {
const item = tab.parent.children[index];
if (!item.headElement.classList.contains("item--pin")) {
- if (item.model instanceof Editor) {
- rootIDs.push(item.model.editor.protyle.block.rootID);
- }
+ rootIDs.push(getRootID(item));
item.parent.removeTab(item.id, true);
index--;
}