浏览代码

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

Vanessa 1 年之前
父节点
当前提交
0dde702ba6
共有 5 个文件被更改,包括 30 次插入15 次删除
  1. 0 5
      app/src/boot/onGetConfig.ts
  2. 14 1
      app/src/layout/Wnd.ts
  3. 6 6
      app/src/layout/dock/index.ts
  4. 9 2
      app/src/layout/tabUtil.ts
  5. 1 1
      app/src/layout/util.ts

+ 0 - 5
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;

+ 14 - 1
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) {

+ 6 - 6
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();
     }
 

+ 9 - 2
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);
 };
 

+ 1 - 1
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) {