diff --git a/app/src/boot/onGetConfig.ts b/app/src/boot/onGetConfig.ts index 8d115998d..7b6d7863b 100644 --- a/app/src/boot/onGetConfig.ts +++ b/app/src/boot/onGetConfig.ts @@ -92,6 +92,7 @@ export const onGetConfig = (isStart: boolean, app: App) => { adjustLayout(); resizeTabs(); resizeTopBar(); + setTabPosition(true); window.siyuan.menus.menu.resetPosition(); firstResize = true; if (getSelection().rangeCount > 0) { diff --git a/app/src/layout/util.ts b/app/src/layout/util.ts index 110c220a5..c40591a77 100644 --- a/app/src/layout/util.ts +++ b/app/src/layout/util.ts @@ -849,6 +849,7 @@ export const addResize = (obj: Layout | Wnd, after = true) => { documentSelf.onselectstart = null; documentSelf.onselect = null; adjustLayout(isWindow() ? window.siyuan.layout.centerLayout : undefined); + setTabPosition(true); resizeTabs(); if (!isWindow()) { window.siyuan.layout.leftDock.setSize(); diff --git a/app/src/plugin/index.ts b/app/src/plugin/index.ts index 41dae0bc8..f7f784e4a 100644 --- a/app/src/plugin/index.ts +++ b/app/src/plugin/index.ts @@ -19,6 +19,7 @@ import {Constants} from "../constants"; import {uninstall} from "./uninstall"; import {addPluginDock, afterLoadPlugin, loadPlugins} from "./loader"; import {normalizeStoragePath} from "../util/pathName"; +import {setTabPosition} from "../window/setHeader"; export class Plugin { private app: App; @@ -224,6 +225,7 @@ export class Plugin { iconElement.addEventListener("click", options.callback); iconElement.setAttribute("data-location", options.position || "right"); resizeTopBar(); + setTabPosition(true); } if (isMobile() && window.siyuan.storage) { if (!window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].includes(iconElement.id)) { diff --git a/app/src/plugin/uninstall.ts b/app/src/plugin/uninstall.ts index da06a8a67..337e82712 100644 --- a/app/src/plugin/uninstall.ts +++ b/app/src/plugin/uninstall.ts @@ -50,7 +50,7 @@ export const uninstall = (app: App, name: string, isReload: boolean) => { } /// #if !MOBILE resizeTopBar(); - setTabPosition(); + setTabPosition(true); // rm statusBar plugin.statusBarIcons.forEach(item => { item.remove(); diff --git a/app/src/window/setHeader.ts b/app/src/window/setHeader.ts index 7041c44a3..832d8808b 100644 --- a/app/src/window/setHeader.ts +++ b/app/src/window/setHeader.ts @@ -5,12 +5,12 @@ import {Editor} from "../editor"; import {Asset} from "../asset"; import {Constants} from "../constants"; -export const setTabPosition = () => { +export const setTabPosition = (onlyPadding = false) => { const isWindowMode = isWindow(); const wndsTemp: Wnd[] = []; if (isWindowMode) { getAllWnds(window.siyuan.layout.layout, wndsTemp); - } else if (window.siyuan.config.appearance.hideToolbar){ + } else if (window.siyuan.config.appearance.hideToolbar) { if (!window.siyuan.layout.centerLayout) { return; } @@ -22,19 +22,47 @@ export const setTabPosition = () => { } const centerRect = (isWindowMode ? window.siyuan.layout.layout : window.siyuan.layout.centerLayout).element.getBoundingClientRect(); - const dragRect = document.getElementById("drag")?.getBoundingClientRect() || { left: 0, right: 0 }; + const dragRect = document.getElementById("drag")?.getBoundingClientRect() || {left: 0, right: 0}; const paddingLeft = ("darwin" === window.siyuan.config.system.os && isWindowMode) ? parseInt(getComputedStyle(document.body).getPropertyValue("--b3-toolbar-left-mac")) : dragRect.left - centerRect.left; const paddingRight = isWindowMode ? document.querySelector(".toolbar__window").clientWidth : centerRect.right - dragRect.right; - wndsTemp.forEach(async item => { - item.element.classList.remove("layout__wnd--right", "layout__wnd--left", "layout__wnd--center"); - (item.element.querySelector(".layout-tab-container") as HTMLElement).style.backgroundColor = ""; + wndsTemp.forEach(item => { const headerElement = item.headersElement.parentElement; const rect = headerElement.getBoundingClientRect(); - const dragElement = headerElement.querySelector(".item--readonly .fn__flex-1") as HTMLElement; headerElement.style.paddingLeft = ""; (headerElement.lastElementChild as HTMLElement).style.marginRight = ""; + headerElement.style.visibility = ""; + if (rect.top <= 0) { + // header padding + if (rect.left - 1 <= centerRect.left) { + headerElement.style.paddingLeft = paddingLeft + "px"; + } else if (rect.left < dragRect.left) { + headerElement.style.paddingLeft = (dragRect.left - rect.left) + "px"; + } + + if (rect.right + 1 >= centerRect.right) { + if (paddingRight + headerElement.lastElementChild.clientWidth > rect.width) { + headerElement.style.visibility = "hidden"; + } else { + (headerElement.lastElementChild as HTMLElement).style.marginRight = paddingRight + "px"; + } + } else if (rect.right > dragRect.right) { + if (paddingRight + headerElement.lastElementChild.clientWidth > rect.width) { + headerElement.style.visibility = "hidden"; + } else { + (headerElement.lastElementChild as HTMLElement).style.marginRight = (rect.right - dragRect.right) + "px"; + } + } + } + + if (onlyPadding) { + return; + } + + item.element.classList.remove("layout__wnd--right", "layout__wnd--left", "layout__wnd--center"); + (item.element.querySelector(".layout-tab-container") as HTMLElement).style.backgroundColor = ""; + const dragElement = headerElement.querySelector(".item--readonly .fn__flex-1") as HTMLElement; if (rect.top <= 0) { // empty if (headerElement.classList.contains("fn__none")) { @@ -54,14 +82,6 @@ export const setTabPosition = () => { dragElement.parentElement.parentElement.style.minWidth = "95px"; dragElement.style.height = dragElement.parentElement.clientHeight + "px"; (dragElement.style as CSSStyleDeclarationElectron).WebkitAppRegion = "drag"; - - // header padding - if (rect.left - 1 <= centerRect.left) { - headerElement.style.paddingLeft = paddingLeft + "px"; - } - if (rect.right + 1 >= centerRect.right) { - (headerElement.lastElementChild as HTMLElement).style.marginRight = paddingRight + "px"; - } } else { dragElement.parentElement.parentElement.style.minWidth = ""; dragElement.style.height = "";