Procházet zdrojové kódy

:art: fix https://github.com/siyuan-note/siyuan/issues/7803

Vanessa před 2 roky
rodič
revize
ddfaf6bdba

+ 3 - 0
app/src/editor/util.ts

@@ -124,6 +124,9 @@ const openFile = (options: IOpenFileOptions) => {
             if ((jsonObj.children.rootId && jsonObj.children.rootId === options.rootID) ||
                 (jsonObj.children.path && jsonObj.children.path === options.assetPath)) {
                 item.focus();
+                if (options.assetPath) {
+                    item.webContents.executeJavaScript(`window.newWindow.positionPDF("${options.assetPath}", ${typeof options.page === "number" ? options.page : `"${options.page}"`})`);
+                }
                 hasOpen = true;
                 return true;
             }

+ 0 - 1
app/src/protyle/method.ts

@@ -31,7 +31,6 @@ class Protyle {
     public static plantumlRender = plantumlRender;
 }
 
-// @ts-ignore
 // 由于 https://github.com/siyuan-note/siyuan/issues/7800,先临时解决一下
 window.Protyle = Protyle;
 

+ 7 - 3
app/src/types/index.d.ts

@@ -31,8 +31,6 @@ type TBazaarType = "templates" | "icons" | "widgets" | "themes"
 declare module "blueimp-md5"
 
 interface Window {
-    __localStorage__removeItem: (key: string) => void
-    __localStorage__setItem: (key: string, value: string) => void
     dataLayer: any[]
     siyuan: ISiyuan
     webkit: any
@@ -47,6 +45,12 @@ interface Window {
         getBlockURL(): string
     }
 
+    newWindow: {
+        positionPDF(pathStr: string, page: string | number): void
+    }
+
+    Protyle: import("../protyle/method").default
+
     goBack(): void
 
     showKeyboardToolbar(height: number): void
@@ -609,7 +613,7 @@ declare interface IBlockTree {
 }
 
 declare interface IBlock {
-    riffCardReps? :number   // 闪卡复习次数
+    riffCardReps?: number   // 闪卡复习次数
     depth?: number,
     box?: string;
     path?: string;

+ 11 - 0
app/src/window/global/positionPDF.ts

@@ -0,0 +1,11 @@
+import {getAllTabs} from "../../layout/getAll";
+import {Asset} from "../../asset";
+
+export const positionPDF = (pathStr: string, page: string | number) => {
+    getAllTabs().forEach((tab) => {
+        if (tab.model instanceof Asset && tab.model.pdfObject && tab.model.path === pathStr) {
+            tab.parent.switchTab(tab.headElement);
+            tab.model.goToPage(page);
+        }
+    })
+}

+ 6 - 0
app/src/window/index.ts

@@ -20,6 +20,7 @@ import {initMessage} from "../dialog/message";
 import {getAllTabs} from "../layout/getAll";
 import {getLocalStorage} from "../protyle/util/compatibility";
 import {init} from "../window/init";
+import {positionPDF} from "./global/positionPDF";
 
 class App {
     constructor() {
@@ -141,3 +142,8 @@ class App {
 }
 
 new App();
+
+// 再次点击新窗口已打开的 PDF 时,需进行定位
+window.newWindow = {
+    positionPDF: positionPDF
+}