Vanessa 2023-12-17 12:17:22 +08:00
parent 97af8f874b
commit 0dde702ba6
5 changed files with 30 additions and 15 deletions

View file

@ -215,11 +215,6 @@ export const initWindow = async (app: App) => {
if (getSelection().rangeCount > 0) {
focusByRange(getSelection().getRangeAt(0));
}
exportLayout({
reload: false,
onlyData: false,
errorExit: false
});
window.siyuan.altIsPressed = false;
window.siyuan.ctrlIsPressed = false;
window.siyuan.shiftIsPressed = false;

View file

@ -1,6 +1,7 @@
import {Layout} from "./index";
import {genUUID} from "../util/genID";
import {
exportLayout,
getInstanceById,
getWndByLayout, JSONToCenter,
newModelByInitData, pdfIsLoading,
@ -279,6 +280,11 @@ export class Wnd {
} else {
oldTab.parent.children.push(tempTab);
}
exportLayout({
reload: false,
onlyData: false,
errorExit: false
});
});
this.element.addEventListener("dragenter", (event: DragEvent & { target: HTMLElement }) => {
@ -492,7 +498,7 @@ export class Wnd {
}
}
public addTab(tab: Tab, keepCursor = false) {
public addTab(tab: Tab, keepCursor = false, saveLayout = true) {
if (keepCursor) {
tab.headElement?.classList.remove("item--focus");
tab.panelElement.classList.add("fn__none");
@ -560,6 +566,13 @@ export class Wnd {
setTabPosition();
setModelsHash();
/// #endif
if (saveLayout) {
exportLayout({
reload: false,
onlyData: false,
errorExit: false
});
}
}
private renderTabList(target: HTMLElement) {

View file

@ -102,8 +102,8 @@ export class Dock {
// 初始化文件树
this.element.querySelectorAll(".dock__item").forEach(item => {
if (item.getAttribute("data-type") === "file" && !item.classList.contains("dock__item--active")) {
this.toggleModel("file", true);
this.toggleModel("file");
this.toggleModel("file", true, false, false, false);
this.toggleModel("file", false, false, false, false);
}
});
@ -111,7 +111,7 @@ export class Dock {
this.resizeElement.classList.add("fn__none");
} else {
activeElements.forEach(item => {
this.toggleModel(item.getAttribute("data-type"), true);
this.toggleModel(item.getAttribute("data-type"), true, false, false, false);
});
}
this.element.addEventListener("click", (event) => {
@ -320,7 +320,7 @@ export class Dock {
this.layout.element.querySelector(".layout__tab--active")?.classList.remove("layout__tab--active");
}
public toggleModel(type: string, show = false, close = false, hide = false) {
public toggleModel(type: string, show = false, close = false, hide = false, saveLayout = true) {
if (!type) {
return;
}
@ -490,7 +490,7 @@ export class Dock {
});
break;
}
wnd.addTab(tab);
wnd.addTab(tab, false, false);
target.setAttribute("data-id", tab.id);
this.data[type] = tab.model;
setPanelFocus(tab.panelElement);
@ -578,7 +578,7 @@ export class Dock {
anotherWnd.element.style.height = "";
anotherWnd.element.style.width = "";
}
resizeTabs();
resizeTabs(saveLayout);
this.showDock();
}

View file

@ -1,5 +1,5 @@
import {Tab} from "./Tab";
import {getInstanceById, newModelByInitData} from "./util";
import {exportLayout, getInstanceById, newModelByInitData} from "./util";
import {getAllModels, getAllTabs} from "./getAll";
import {hideAllElements, hideElements} from "../protyle/ui/hideElements";
import {pdfResize} from "../asset/renderAssets";
@ -84,7 +84,7 @@ export const switchTabByIndex = (index: number) => {
};
let resizeTimeout: number;
export const resizeTabs = () => {
export const resizeTabs = (setLayout = true) => {
clearTimeout(resizeTimeout);
// .layout .fn__flex-shrink {width .15s cubic-bezier(0, 0, .2, 1) 0ms} 时需要再次计算 padding
// PDF 避免分屏多次调用后页码跳转到1 https://github.com/siyuan-note/siyuan/issues/5646
@ -117,6 +117,13 @@ export const resizeTabs = () => {
});
pdfResize();
hideAllElements(["gutter"]);
if (setLayout) {
exportLayout({
reload: false,
onlyData: false,
errorExit: false
});
}
}, 200);
};

View file

@ -301,7 +301,7 @@ export const JSONToCenter = (app: App, json: ILayoutJSON, layout?: Layout | Wnd
if (json.active) {
child.headElement.setAttribute("data-init-active", "true");
}
(layout as Wnd).addTab(child);
(layout as Wnd).addTab(child, false, false);
(layout as Wnd).showHeading();
} else if (json.instance === "Editor" && json.blockId) {
if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {