This commit is contained in:
Vanessa 2023-03-29 09:12:04 +08:00
parent 42dc3712c1
commit ddfaf6bdba
5 changed files with 27 additions and 4 deletions

View File

@ -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;
}

View File

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

View File

@ -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;

View File

@ -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);
}
})
}

View File

@ -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
}