mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-02 02:40:15 +01:00
This commit is contained in:
parent
f85b5d6740
commit
11adc35e10
13 changed files with 136 additions and 64 deletions
37
app/src/window/global/function.ts
Normal file
37
app/src/window/global/function.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
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.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
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
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);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
@ -20,7 +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";
|
||||
import {positionPDF, switchTabById} from "./global/function";
|
||||
|
||||
class App {
|
||||
constructor() {
|
||||
|
|
@ -145,5 +145,6 @@ new App();
|
|||
|
||||
// 再次点击新窗口已打开的 PDF 时,需进行定位
|
||||
window.newWindow = {
|
||||
positionPDF: positionPDF
|
||||
positionPDF: positionPDF,
|
||||
switchTabById: switchTabById
|
||||
};
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ export const init = () => {
|
|||
}]
|
||||
});
|
||||
window.siyuan.layout.centerLayout = window.siyuan.layout.layout;
|
||||
|
||||
});
|
||||
initStatus(true);
|
||||
initWindow();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@ import {isWindow} from "../util/functions";
|
|||
import {Wnd} from "../layout/Wnd";
|
||||
import {getCurrentWindow} from "@electron/remote";
|
||||
import {Layout} from "../layout";
|
||||
import {getAllTabs} from "../layout/getAll";
|
||||
import {Editor} from "../editor";
|
||||
import {Asset} from "../asset";
|
||||
import {Constants} from "../constants";
|
||||
|
||||
const getAllWnds = (layout: Layout, wnds: Wnd[]) => {
|
||||
for (let i = 0; i < layout.children.length; i++) {
|
||||
|
|
@ -50,3 +54,25 @@ export const setTabPosition = () => {
|
|||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
export const setModelsHash = () => {
|
||||
if (!isWindow()) {
|
||||
return
|
||||
}
|
||||
let hash = ""
|
||||
getAllTabs().forEach(tab => {
|
||||
if (!tab.model) {
|
||||
const initTab = tab.headElement.getAttribute("data-initdata");
|
||||
if (initTab) {
|
||||
const initTabData = JSON.parse(initTab);
|
||||
hash += initTabData.rootId + Constants.ZWSP
|
||||
}
|
||||
} else if (tab.model instanceof Editor) {
|
||||
hash += tab.model.editor.protyle.block.rootID + Constants.ZWSP
|
||||
} else if (tab.model instanceof Asset) {
|
||||
hash += tab.model.path + Constants.ZWSP
|
||||
}
|
||||
})
|
||||
window.location.hash = hash
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue