This commit is contained in:
Vanessa 2023-09-10 16:42:24 +08:00
parent 64b6001947
commit 7e8e6167ff
4 changed files with 6 additions and 48 deletions

View file

@ -1,37 +0,0 @@
import {getAllTabs} from "../../layout/getAll";
import {Asset} from "../../asset";
import {Editor} from "../../editor";
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);
}
});
};
export const switchTabById = (id: string) => {
getAllTabs().find((tab) => {
if (!tab.model) {
const initTab = tab.headElement.getAttribute("data-initdata");
if (initTab) {
const initTabData = JSON.parse(initTab);
if (initTabData.instance === "Editor" && initTabData.rootId === id) {
tab.parent.switchTab(tab.headElement);
return true;
}
}
} else if (tab.model instanceof Editor) {
if (tab.model.editor.protyle.block.rootID === id) {
tab.parent.switchTab(tab.headElement);
return true;
}
} else if (tab.model instanceof Asset) {
if (tab.model.path === id) {
tab.parent.switchTab(tab.headElement);
return true;
}
}
});
};

View file

@ -7,7 +7,7 @@ import {addScript, addScriptSync} from "../protyle/util/addScript";
import {genUUID} from "../util/genID";
import {fetchGet, fetchPost} from "../util/fetch";
import {addBaseURL, setNoteBook} from "../util/pathName";
import {openFileById} from "../editor/util";
import {openFile, openFileById} from "../editor/util";
import {
processSync, progressBackgroundTask,
progressLoading,
@ -19,7 +19,6 @@ import {initMessage} from "../dialog/message";
import {getAllTabs} from "../layout/getAll";
import {getLocalStorage} from "../protyle/util/compatibility";
import {init} from "../window/init";
import {positionPDF, switchTabById} from "./global/function";
import {loadPlugins} from "../plugin/loader";
class App {
@ -152,6 +151,5 @@ new App();
// 再次点击新窗口已打开的 PDF 时,需进行定位
window.newWindow = {
positionPDF: positionPDF,
switchTabById: switchTabById
openFile: openFile,
};