Browse Source

:bug: fix https://github.com/siyuan-note/siyuan/issues/5740

Vanessa 2 years ago
parent
commit
87f681cce2
3 changed files with 26 additions and 2 deletions
  1. 24 1
      app/src/editor/util.ts
  2. 1 1
      app/src/layout/Wnd.ts
  3. 1 0
      app/src/layout/util.ts

+ 24 - 1
app/src/editor/util.ts

@@ -2,7 +2,7 @@ import {Tab} from "../layout/Tab";
 import {Editor} from "./index";
 import {Editor} from "./index";
 import {Wnd} from "../layout/Wnd";
 import {Wnd} from "../layout/Wnd";
 import {getDockByType, getInstanceById, getWndByLayout} from "../layout/util";
 import {getDockByType, getInstanceById, getWndByLayout} from "../layout/util";
-import {getAllModels} from "../layout/getAll";
+import {getAllModels, getAllTabs} from "../layout/getAll";
 import {highlightById, scrollCenter} from "../util/highlightById";
 import {highlightById, scrollCenter} from "../util/highlightById";
 import {getDisplayName, pathPosix} from "../util/pathName";
 import {getDisplayName, pathPosix} from "../util/pathName";
 import {Constants} from "../constants";
 import {Constants} from "../constants";
@@ -96,6 +96,29 @@ const openFile = (options: IOpenFileOptions) => {
             switchEditor(editor, options, allModels);
             switchEditor(editor, options, allModels);
             return true;
             return true;
         }
         }
+        // 没有初始化的页签无法检测到
+        const hasEditor = getAllTabs().find(item => {
+            const initData = item.headElement.getAttribute("data-initdata");
+            if (initData) {
+                const initObj = JSON.parse(initData);
+                if (initObj.rootID === options.rootID || initObj.blockId === options.rootID) {
+                    initObj.blockId = options.id
+                    initObj.mode = options.mode
+                    if (options.zoomIn) {
+                        initObj.action = [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS]
+                    } else {
+                        initObj.action = options.action
+                    }
+                    delete initObj.scrollAttr
+                    item.headElement.setAttribute("data-initdata", JSON.stringify(initObj));
+                    item.parent.switchTab(item.headElement);
+                    return true;
+                }
+            }
+        });
+        if (hasEditor) {
+            return;
+        }
     }
     }
 
 
     let wnd: Wnd = undefined;
     let wnd: Wnd = undefined;

+ 1 - 1
app/src/layout/Wnd.ts

@@ -318,7 +318,7 @@ export class Wnd {
                 tab: currentTab,
                 tab: currentTab,
                 blockId: json.blockId,
                 blockId: json.blockId,
                 mode: json.mode,
                 mode: json.mode,
-                action: [json.action],
+                action: typeof json.action === "string" ? [json.action] : json.action,
                 scrollAttr: json.scrollAttr,
                 scrollAttr: json.scrollAttr,
             }));
             }));
             currentTab.headElement.removeAttribute("data-initdata");
             currentTab.headElement.removeAttribute("data-initdata");

+ 1 - 0
app/src/layout/util.ts

@@ -322,6 +322,7 @@ export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any) => {
         json.instance = "Tab";
         json.instance = "Tab";
     } else if (layout instanceof Editor) {
     } else if (layout instanceof Editor) {
         json.blockId = layout.editor.protyle.block.id;
         json.blockId = layout.editor.protyle.block.id;
+        json.rootID = layout.editor.protyle.block.rootID;
         json.mode = layout.editor.protyle.preview.element.classList.contains("fn__none") ? "wysiwyg" : "preview";
         json.mode = layout.editor.protyle.preview.element.classList.contains("fn__none") ? "wysiwyg" : "preview";
         json.action = layout.editor.protyle.block.showAll ? Constants.CB_GET_ALL : "";
         json.action = layout.editor.protyle.block.showAll ? Constants.CB_GET_ALL : "";
         json.instance = "Editor";
         json.instance = "Editor";