diff --git a/app/src/boot/onGetConfig.ts b/app/src/boot/onGetConfig.ts index 09480ccff..e15d73acd 100644 --- a/app/src/boot/onGetConfig.ts +++ b/app/src/boot/onGetConfig.ts @@ -215,11 +215,6 @@ export const initWindow = async (app: App) => { if (getSelection().rangeCount > 0) { focusByRange(getSelection().getRangeAt(0)); } - exportLayout({ - reload: false, - onlyData: false, - errorExit: false - }); window.siyuan.altIsPressed = false; window.siyuan.ctrlIsPressed = false; window.siyuan.shiftIsPressed = false; diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.ts index a3cb753ab..d9e0340ff 100644 --- a/app/src/layout/Wnd.ts +++ b/app/src/layout/Wnd.ts @@ -1,6 +1,7 @@ import {Layout} from "./index"; import {genUUID} from "../util/genID"; import { + exportLayout, getInstanceById, getWndByLayout, JSONToCenter, newModelByInitData, pdfIsLoading, @@ -279,6 +280,11 @@ export class Wnd { } else { oldTab.parent.children.push(tempTab); } + exportLayout({ + reload: false, + onlyData: false, + errorExit: false + }); }); this.element.addEventListener("dragenter", (event: DragEvent & { target: HTMLElement }) => { @@ -492,7 +498,7 @@ export class Wnd { } } - public addTab(tab: Tab, keepCursor = false) { + public addTab(tab: Tab, keepCursor = false, saveLayout = true) { if (keepCursor) { tab.headElement?.classList.remove("item--focus"); tab.panelElement.classList.add("fn__none"); @@ -560,6 +566,13 @@ export class Wnd { setTabPosition(); setModelsHash(); /// #endif + if (saveLayout) { + exportLayout({ + reload: false, + onlyData: false, + errorExit: false + }); + } } private renderTabList(target: HTMLElement) { diff --git a/app/src/layout/dock/index.ts b/app/src/layout/dock/index.ts index 54b5e3b87..76a580443 100644 --- a/app/src/layout/dock/index.ts +++ b/app/src/layout/dock/index.ts @@ -102,8 +102,8 @@ export class Dock { // 初始化文件树 this.element.querySelectorAll(".dock__item").forEach(item => { if (item.getAttribute("data-type") === "file" && !item.classList.contains("dock__item--active")) { - this.toggleModel("file", true); - this.toggleModel("file"); + this.toggleModel("file", true, false, false, false); + this.toggleModel("file", false, false, false, false); } }); @@ -111,7 +111,7 @@ export class Dock { this.resizeElement.classList.add("fn__none"); } else { activeElements.forEach(item => { - this.toggleModel(item.getAttribute("data-type"), true); + this.toggleModel(item.getAttribute("data-type"), true, false, false, false); }); } this.element.addEventListener("click", (event) => { @@ -320,7 +320,7 @@ export class Dock { this.layout.element.querySelector(".layout__tab--active")?.classList.remove("layout__tab--active"); } - public toggleModel(type: string, show = false, close = false, hide = false) { + public toggleModel(type: string, show = false, close = false, hide = false, saveLayout = true) { if (!type) { return; } @@ -490,7 +490,7 @@ export class Dock { }); break; } - wnd.addTab(tab); + wnd.addTab(tab, false, false); target.setAttribute("data-id", tab.id); this.data[type] = tab.model; setPanelFocus(tab.panelElement); @@ -578,7 +578,7 @@ export class Dock { anotherWnd.element.style.height = ""; anotherWnd.element.style.width = ""; } - resizeTabs(); + resizeTabs(saveLayout); this.showDock(); } diff --git a/app/src/layout/tabUtil.ts b/app/src/layout/tabUtil.ts index 05d14de5c..e69a3fb64 100644 --- a/app/src/layout/tabUtil.ts +++ b/app/src/layout/tabUtil.ts @@ -1,5 +1,5 @@ import {Tab} from "./Tab"; -import {getInstanceById, newModelByInitData} from "./util"; +import {exportLayout, getInstanceById, newModelByInitData} from "./util"; import {getAllModels, getAllTabs} from "./getAll"; import {hideAllElements, hideElements} from "../protyle/ui/hideElements"; import {pdfResize} from "../asset/renderAssets"; @@ -84,7 +84,7 @@ export const switchTabByIndex = (index: number) => { }; let resizeTimeout: number; -export const resizeTabs = () => { +export const resizeTabs = (setLayout = true) => { clearTimeout(resizeTimeout); // .layout .fn__flex-shrink {width .15s cubic-bezier(0, 0, .2, 1) 0ms} 时需要再次计算 padding // PDF 避免分屏多次调用后,页码跳转到1 https://github.com/siyuan-note/siyuan/issues/5646 @@ -117,6 +117,13 @@ export const resizeTabs = () => { }); pdfResize(); hideAllElements(["gutter"]); + if (setLayout) { + exportLayout({ + reload: false, + onlyData: false, + errorExit: false + }); + } }, 200); }; diff --git a/app/src/layout/util.ts b/app/src/layout/util.ts index 419ca7a45..c97fae8b2 100644 --- a/app/src/layout/util.ts +++ b/app/src/layout/util.ts @@ -301,7 +301,7 @@ export const JSONToCenter = (app: App, json: ILayoutJSON, layout?: Layout | Wnd if (json.active) { child.headElement.setAttribute("data-init-active", "true"); } - (layout as Wnd).addTab(child); + (layout as Wnd).addTab(child, false, false); (layout as Wnd).showHeading(); } else if (json.instance === "Editor" && json.blockId) { if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {