瀏覽代碼

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

Vanessa 9 月之前
父節點
當前提交
39e21df87e
共有 4 個文件被更改,包括 30 次插入26 次删除
  1. 2 2
      app/src/card/openCard.ts
  2. 2 4
      app/src/menus/util.ts
  3. 3 3
      app/src/window/init.ts
  4. 23 17
      app/src/window/openNewWindow.ts

+ 2 - 2
app/src/card/openCard.ts

@@ -448,7 +448,7 @@ export const bindCardEvent = async (options: {
                     icon: "iconOpenWindow",
                     label: window.siyuan.languages.openByNewWindow,
                     click() {
-                        const json = {
+                        const json = [{
                             "title": window.siyuan.languages.spaceRepetition,
                             "icon": "iconRiffCard",
                             "instance": "Tab",
@@ -461,7 +461,7 @@ export const bindCardEvent = async (options: {
                                     "title": options.title
                                 }
                             }
-                        };
+                        }];
                         ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, {
                             // 需要 encode, 否则 https://github.com/siyuan-note/siyuan/issues/9343
                             url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${encodeURIComponent(JSON.stringify(json))}`

+ 2 - 4
app/src/menus/util.ts

@@ -125,9 +125,7 @@ export const openEditorTab = (app: App, ids: string[], notebookId?: string, path
         label: window.siyuan.languages.openByNewWindow,
         icon: "iconOpenWindow",
         click() {
-            ids.forEach((id) => {
-                openNewWindowById(id);
-            });
+            openNewWindowById(ids);
         }
     });
     /// #endif
@@ -170,7 +168,7 @@ export const openEditorTab = (app: App, ids: string[], notebookId?: string, path
     /// #endif
 };
 
-export const copyPNGByLink = (link:string) => {
+export const copyPNGByLink = (link: string) => {
     if (isInAndroid()) {
         window.JSAndroid.writeImageClipboard(link);
         return;

+ 3 - 3
app/src/window/init.ts

@@ -27,8 +27,8 @@ export const init = (app: App) => {
             afterLayout(app);
             return;
         }
-        const tabJSON = JSON.parse(getSearch("json"));
-        tabJSON.active = true;
+        const tabsJSON = JSON.parse(getSearch("json"));
+        tabsJSON[tabsJSON.length - 1].active = true;
         JSONToCenter(app, {
             direction: "lr",
             resize: "lr",
@@ -37,7 +37,7 @@ export const init = (app: App) => {
             instance: "Layout",
             children: [{
                 instance: "Wnd",
-                children: [tabJSON]
+                children: tabsJSON
             }]
         });
         window.siyuan.layout.centerLayout = window.siyuan.layout.layout;

+ 23 - 17
app/src/window/openNewWindow.ts

@@ -4,7 +4,7 @@ import {ipcRenderer} from "electron";
 /// #endif
 import {Constants} from "../constants";
 import {Tab} from "../layout/Tab";
-import {fetchPost} from "../util/fetch";
+import {fetchSyncPost} from "../util/fetch";
 import {showMessage} from "../dialog/message";
 import {getDisplayName, pathPosix} from "../util/pathName";
 import {getSearch} from "../util/functions";
@@ -27,19 +27,25 @@ export const openNewWindow = (tab: Tab, options: windowOptions = {}) => {
         width: options.width,
         height: options.height,
         // 需要 encode, 否则 https://github.com/siyuan-note/siyuan/issues/9343
-        url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${encodeURIComponent(JSON.stringify(json))}`
+        url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${encodeURIComponent(JSON.stringify([json]))}`
     });
     /// #endif
     tab.parent.removeTab(tab.id);
 };
 
-export const openNewWindowById = (id: string, options: windowOptions = {}) => {
-    fetchPost("/api/block/getBlockInfo", {id}, (response) => {
+export const openNewWindowById = async (id: string | string[], options: windowOptions = {}) => {
+    let ids = id;
+    if (typeof ids === "string") {
+        ids = [ids];
+    }
+    const json = [];
+    for (let i = 0; i < ids.length; i++) {
+        const response = await fetchSyncPost("/api/block/getBlockInfo", {id: ids[i]});
         if (response.code === 3) {
             showMessage(response.msg);
             return;
         }
-        const json: any = {
+        json.push({
             title: response.data.rootTitle,
             docIcon: response.data.rootIcon,
             pin: false,
@@ -48,22 +54,22 @@ export const openNewWindowById = (id: string, options: windowOptions = {}) => {
             action: "Tab",
             children: {
                 notebookId: response.data.box,
-                blockId: id,
+                blockId: ids[i],
                 rootId: response.data.rootID,
                 mode: "wysiwyg",
                 instance: "Editor",
-                action: response.data.rootID === id ? Constants.CB_GET_SCROLL : Constants.CB_GET_ALL
+                action: response.data.rootID === ids[i] ? Constants.CB_GET_SCROLL : Constants.CB_GET_ALL
             }
-        };
-        /// #if !BROWSER
-        ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, {
-            position: options.position,
-            width: options.width,
-            height: options.height,
-            url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${encodeURIComponent(JSON.stringify(json))}`
         });
-        /// #endif
+    }
+    /// #if !BROWSER
+    ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, {
+        position: options.position,
+        width: options.width,
+        height: options.height,
+        url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${encodeURIComponent(JSON.stringify(json))}`
     });
+    /// #endif
 };
 
 export const openAssetNewWindow = (assetPath: string, options: windowOptions = {}) => {
@@ -78,7 +84,7 @@ export const openAssetNewWindow = (assetPath: string, options: windowOptions = {
         } else if (Constants.SIYUAN_ASSETS_VIDEO.includes(suffix)) {
             docIcon = "iconVideo";
         }
-        const json: any = {
+        const json: any = [{
             title: getDisplayName(assetPath),
             docIcon,
             pin: false,
@@ -90,7 +96,7 @@ export const openAssetNewWindow = (assetPath: string, options: windowOptions = {
                 page: parseInt(getSearch("page", assetPath)),
                 instance: "Asset",
             }
-        };
+        }];
         ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, {
             position: options.position,
             width: options.width,