From 44491e4442a8630d4cf5bd0c56fc745711b7acc4 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Mon, 9 Dec 2024 11:23:46 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/13390 --- app/src/layout/Wnd.ts | 2 +- app/src/layout/util.ts | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.ts index 8f451af8e..6c9043529 100644 --- a/app/src/layout/Wnd.ts +++ b/app/src/layout/Wnd.ts @@ -445,7 +445,7 @@ export class Wnd { }); // 在 JSONToLayout 中进行 focus if (!isInitActive) { - setPanelFocus(this.headersElement.parentElement.parentElement); + setPanelFocus(this.headersElement.parentElement.parentElement, isSaveLayout); } if (currentTab && currentTab.headElement) { const initData = currentTab.headElement.getAttribute("data-initdata"); diff --git a/app/src/layout/util.ts b/app/src/layout/util.ts index 753d73749..2d125d8f0 100644 --- a/app/src/layout/util.ts +++ b/app/src/layout/util.ts @@ -306,6 +306,8 @@ const JSONToDock = (json: any, app: App) => { window.siyuan.layout.bottomDock = new Dock({position: "Bottom", data: json.bottom, app}); }; +const removedTabs: Tab[] = [] + export const JSONToCenter = ( app: App, json: Config.TUILayoutItem, @@ -432,8 +434,10 @@ export const JSONToCenter = ( json.children.forEach((item: any) => { JSONToCenter(app, item, layout ? child : window.siyuan.layout.layout); }); - } else { + } else if (json.children && Object.keys(json.children).length > 0) { JSONToCenter(app, json.children, child); + } else if (child instanceof Tab) { + removedTabs.push(child) } } }; @@ -510,6 +514,10 @@ export const JSONToLayout = (app: App, isStart: boolean) => { if (latestTabHeaderElement) { setPanelFocus(latestTabHeaderElement.parentElement.parentElement.parentElement, false); } + // 移除没有数据的页签 https://github.com/siyuan-note/siyuan/issues/13390 + removedTabs.forEach(item => { + item.parent.removeTab(item.id); + }) } // 需放在 tab.parent.switchTab 后,否则当前 tab 永远为最后一个 app.plugins.forEach(item => {