Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Preserve normal dock layout when revealing hidden bars https://github.com/siyuan-note/siyuan/issues/20833

Danielc58e9000fe5c
diff --git a/app/src/assets/scss/business/_layout.scss b/app/src/assets/scss/business/_layout.scss
index 040d8dc7bc..0e1cc3e773 100644
--- a/app/src/assets/scss/business/_layout.scss
+++ b/app/src/assets/scss/business/_layout.scss
@@ -435,20 +435,6 @@
overscroll-behavior-y: contain;
scrollbar-width: none;
- &--float {
- position: fixed;
- left: 0;
- height: auto;
- border-radius: var(--b3-border-radius-b) 0 0 var(--b3-border-radius-b);
- background-color: var(--b3-body-background);
-
- &#dockRight {
- left: auto;
- right: 0;
- border-radius: 0 var(--b3-border-radius-b) var(--b3-border-radius-b) 0;
- }
- }
-
&::-webkit-scrollbar {
display: none;
}
diff --git a/app/src/boot/globalEvent/mousemove.ts b/app/src/boot/globalEvent/mousemove.ts
index efe9aa6ee5..be18bb6431 100644
--- a/app/src/boot/globalEvent/mousemove.ts
+++ b/app/src/boot/globalEvent/mousemove.ts
@@ -110,7 +110,7 @@ export const windowMouseMove = (event: MouseEvent) => {
!hasClosestByClassName(target, "protyle-util");
const leftDock = window.siyuan.layout.leftDock;
const leftBar = document.getElementById("dockLeft");
- const leftBarWidth = leftBar.classList.contains("dock--float") ? 0 : leftBar.clientWidth;
+ const leftBarWidth = leftBar.clientWidth;
const leftTrigger = canTrigger && inYRange && leftDock.isFloating() && leftDock.layout.element.clientWidth > 0 &&
event.clientX < Math.max(leftBarWidth + 1, 16) &&
// 隐藏停靠栏会导致点击两侧内容触发浮动面板弹出,因此需减小鼠标范围
@@ -123,7 +123,7 @@ export const windowMouseMove = (event: MouseEvent) => {
const rightDock = window.siyuan.layout.rightDock;
const rightBar = document.getElementById("dockRight");
- const rightBarWidth = rightBar.classList.contains("dock--float") ? 0 : rightBar.clientWidth;
+ const rightBarWidth = rightBar.clientWidth;
const rightTrigger = canTrigger && inYRange && rightDock.isFloating() && rightDock.layout.element.clientWidth > 0 &&
event.clientX > window.innerWidth - Math.max(rightBarWidth - 2, 16) &&
(rightBarWidth > 0 || event.clientX > window.innerWidth - 8);
diff --git a/app/src/layout/dock/barVisibility.ts b/app/src/layout/dock/barVisibility.ts
index dd1f758727..0fc647ac2c 100644
--- a/app/src/layout/dock/barVisibility.ts
+++ b/app/src/layout/dock/barVisibility.ts
@@ -4,8 +4,6 @@ export const shouldShowDockBar = (globallyHidden: boolean, hasVisibleEntry: bool
export const shouldShowDockSplit = (hasVisibleEntryBefore: boolean, hasVisibleEntryAfter: boolean) =>
hasVisibleEntryBefore && hasVisibleEntryAfter;
-let floatingBarResizeObserver: ResizeObserver;
-
export const adjustDockPadding = () => {
const layoutElement = window.siyuan.layout?.layout?.children[0]?.element;
const leftDockElement = window.siyuan.layout?.leftDock?.elements[0]?.parentElement;
@@ -14,12 +12,12 @@ export const adjustDockPadding = () => {
if (!layoutElement || !leftDockElement || !rightDockElement) {
return;
}
- if (leftDockElement.classList.contains("fn__none") || leftDockElement.classList.contains("dock--float")) {
+ if (leftDockElement.classList.contains("fn__none")) {
layoutElement.style.marginLeft = "var(--b3-layout-space)";
} else {
layoutElement.style.marginLeft = "";
}
- if (rightDockElement.classList.contains("fn__none") || rightDockElement.classList.contains("dock--float")) {
+ if (rightDockElement.classList.contains("fn__none")) {
layoutElement.style.marginRight = "var(--b3-layout-space)";
} else {
layoutElement.style.marginRight = "";
@@ -32,7 +30,7 @@ export const adjustDockPadding = () => {
};
export const syncDockBarVisibility = () => {
- const floatingBars: HTMLElement[] = [];
+ let changed = false;
document.querySelectorAll<HTMLElement>(".dock").forEach((item) => {
const sections = Array.from(item.querySelectorAll<HTMLElement>(":scope > .dock__items"));
const sectionVisibility = sections.map((section) =>
@@ -46,45 +44,14 @@ export const syncDockBarVisibility = () => {
item.id === "dockRight" ? window.siyuan.layout?.rightDock : undefined;
const floatingPanelOpen = Boolean(dock?.isFloating() && dock.isPanelVisible() &&
!dock.layout.element.classList.contains("fn__none") && dock.layout.element.style.opacity === "1");
- const floating = window.siyuan.config.uiLayout.hideDock && floatingPanelOpen && sectionVisibility.some(Boolean);
- const wasFloating = item.classList.contains("dock--float");
- item.classList.toggle("dock--float", floating);
- item.classList.toggle("fn__none", !shouldShowDockBar(
+ const hidden = !shouldShowDockBar(
window.siyuan.config.uiLayout.hideDock,
sectionVisibility.some(Boolean),
floatingPanelOpen,
- ));
- if (floating) {
- floatingBars.push(item);
- // 临时停靠栏脱离主布局,层级低于面板,避免遮挡面板内的全屏内容。
- const panelRect = dock.layout.element.getBoundingClientRect();
- item.style.top = panelRect.top + "px";
- item.style.bottom = (window.innerHeight - panelRect.bottom) + "px";
- item.style.zIndex = (Number(dock.layout.element.style.zIndex) - 1).toString();
- } else if (wasFloating) {
- item.style.top = "";
- item.style.bottom = "";
- item.style.zIndex = "";
- }
+ );
+ changed = item.classList.contains("fn__none") !== hidden || changed;
+ item.classList.toggle("fn__none", hidden);
});
adjustDockPadding();
- // 面板范围和界面密度变化后,同步临时停靠栏的范围及面板偏移。
- if (floatingBars.length > 0 && !floatingBarResizeObserver) {
- floatingBarResizeObserver = new ResizeObserver(() => {
- for (const dock of [window.siyuan.layout?.leftDock, window.siyuan.layout?.rightDock]) {
- if (dock?.elements[0].parentElement.classList.contains("dock--float")) {
- dock.showDock(true);
- }
- }
- });
- for (const element of [window.siyuan.layout?.leftDock?.layout.element, window.siyuan.layout?.rightDock?.layout.element,
- document.getElementById("dockLeft"), document.getElementById("dockRight")]) {
- if (element) {
- floatingBarResizeObserver.observe(element);
- }
- }
- } else if (floatingBars.length === 0 && floatingBarResizeObserver) {
- floatingBarResizeObserver.disconnect();
- floatingBarResizeObserver = undefined;
- }
+ return changed;
};
diff --git a/app/src/layout/dock/index.ts b/app/src/layout/dock/index.ts
index 8788626f3f..03952aaa9d 100644
--- a/app/src/layout/dock/index.ts
+++ b/app/src/layout/dock/index.ts
@@ -423,7 +423,7 @@ export class Dock {
this.collapsedPanelSize = "";
this.layout.element.classList.remove("fn__none");
this.resizeElement.classList.add("fn__none");
- syncDockBarVisibility();
+ this.syncDockBar();
return false;
}
@@ -475,7 +475,7 @@ export class Dock {
}
}
}
- syncDockBarVisibility();
+ this.syncDockBar();
resizeTabs(false);
setTabPosition(true);
if (resolution.visible) {
@@ -525,7 +525,7 @@ export class Dock {
if (!hasActive && !this.isFloating()) {
this.layout.element.style[this.position === "Bottom" ? "height" : "width"] = "0px";
}
- syncDockBarVisibility();
+ this.syncDockBar();
resizeTabs(isSaveLayout);
setTabPosition(true);
}
@@ -587,6 +587,19 @@ export class Dock {
this.hideDockTimeout = 0;
}
+ private syncDockBar() {
+ if (!syncDockBarVisibility()) {
+ return;
+ }
+ // 临时显示停靠栏时沿用正常占位,并同步编辑区和已展开的底部面板。
+ resizeTabs(false);
+ setTabPosition(true);
+ const bottomDock = window.siyuan.layout.bottomDock;
+ if (this.position !== "Bottom" && bottomDock?.isFloating() && bottomDock.layout.element.style.opacity === "1") {
+ bottomDock.showDock(true);
+ }
+ }
+
public showDock(reset = false) {
this.clearDockHoverTimeout();
if (this.initializing || !this.panelVisible || (!reset && (!this.isFloating() || this.layout.element.style.opacity === "1")) ||
@@ -618,15 +631,15 @@ export class Dock {
this.layout.element.style.opacity = "1";
}
this.layout.element.style.zIndex = (++window.siyuan.zIndex).toString();
- syncDockBarVisibility();
+ this.syncDockBar();
if (this.position === "Left") {
this.layout.element.style.transform = `translateX(${this.elements[0].clientWidth}px)`;
} else if (this.position === "Right") {
this.layout.element.style.transform = `translateX(-${this.elements[0].clientWidth}px)`;
} else if (this.position === "Bottom") {
this.layout.element.style.transform = `translateY(-${document.getElementById("status").offsetHeight}px)`;
- this.layout.element.style.left = (window.siyuan.config.uiLayout.hideDock ? 0 : this.elements[0].clientWidth) + "px";
- this.layout.element.style.right = (window.siyuan.config.uiLayout.hideDock ? 0 : this.elements[1].clientWidth) + "px";
+ this.layout.element.style.left = this.elements[0].clientWidth + "px";
+ this.layout.element.style.right = this.elements[1].clientWidth + "px";
}
// 全屏面板以窗口定位,浮动位移保留到退出全屏时恢复。
const fullscreenElement = this.layout.element.querySelector(".fullscreen");
@@ -683,7 +696,7 @@ export class Dock {
this.elements[0].querySelector(".dock__item--activefocus")?.classList.remove("dock__item--activefocus");
this.elements[1].querySelector(".dock__item--activefocus")?.classList.remove("dock__item--activefocus");
this.layout.element.querySelector(".layout__tab--active")?.classList.remove("layout__tab--active");
- syncDockBarVisibility();
+ this.syncDockBar();
}
public toggleModel(type: TDock | string, show = false, close = false, removeDock = false, isSaveLayout = true,
@@ -1016,7 +1029,7 @@ export class Dock {
anotherWnd.element.style.height = "";
anotherWnd.element.style.width = "";
}
- syncDockBarVisibility();
+ this.syncDockBar();
resizeTabs(isSaveLayout);
if (target.classList.contains("dock__item--active") && !removeDock && this.panelVisible) {
this.showDockAfterResponsiveLayout();
diff --git a/app/tests/dockBarVisibility.test.js b/app/tests/dockBarVisibility.test.js
index 8e8cda34aa..f93c8ed24c 100644
--- a/app/tests/dockBarVisibility.test.js
+++ b/app/tests/dockBarVisibility.test.js
@@ -21,7 +21,8 @@ const browserCases = async (sources, css, template) => {
layouts.classList.add("fn__flex-column");
layouts.innerHTML = '<div id="outer" class="fn__flex fn__flex-1">' +
'<div id="left" class="layout fn__flex-column"></div><div class="layout__resize"></div>' +
- '<div id="center" class="layout__center fn__flex-1">Editor</div><div class="layout__resize"></div>' +
+ '<div id="center" class="layout__center fn__flex-1 fn__flex"><div class="layout-tab-container fn__flex-1">Editor</div></div>' +
+ '<div class="layout__resize"></div>' +
'<div id="right" class="layout fn__flex-column"></div></div><div class="layout__resize"></div>' +
'<div id="bottom" class="layout fn__flex"></div>';
const makeLayout = (id) => {
@@ -38,12 +39,13 @@ const browserCases = async (sources, css, template) => {
window.siyuan = {zIndex: 10, config: {uiLayout: {hideDock: true}, appearance: {hideStatusBar: false}, system: {os: "linux"}},
layout: {layout: {children: [outer, bottom]}, centerLayout: center}};
const bar = load("barVisibility");
+ const resizes = [];
const dependencies = {
...bar, ...load("panelVisibility"),
Constants: {TIMEOUT_DOCK_TOGGLE: 20, TIMEOUT_TRANSITION: 20, ATTRIBUTE_DOCK_WIDTH: "data-width"},
bindPanelTransitionGuard() {}, isTouchHoverInput: () => false,
isWindow: () => false, isAbove: (a, b) => Number(a.style.zIndex) > Number(b.style.zIndex),
- resizeTabs() {}, setTabPosition() {}, adjustLayout() {}, setPanelFocus() {},
+ resizeTabs(save) { resizes.push(save); }, setTabPosition() {}, adjustLayout() {}, setPanelFocus() {},
recordBeforeResizeTop() {}, clearBeforeResizeTop() {},
hasClosestByClassName: (element, name) => element?.closest?.("." + name),
};
@@ -59,8 +61,8 @@ const browserCases = async (sources, css, template) => {
const dock = docks[position];
for (const suffix of ["one", "two"]) {
const type = position + suffix;
- dock.elements[0].insertAdjacentHTML("beforeend", `<button class="dock__item" data-type="${type}"
- data-entry-id="plugin:test:${type}" data-id="${type}" data-index="0" data-width="240" data-height="180">${suffix}</button>`);
+ dock.elements[0].insertAdjacentHTML("beforeend", `<span class="dock__item" data-type="${type}"
+ data-entry-id="plugin:test:${type}" data-id="${type}" data-index="0" data-width="240" data-height="180">${suffix}</span>`);
dock.layout.children[0].element.firstElementChild.insertAdjacentHTML("beforeend",
`<div data-id="${type}" class="fn__none"><input class="b3-text-field"></div>`);
}
@@ -71,6 +73,12 @@ const browserCases = async (sources, css, template) => {
const {x, y, width, height} = element.getBoundingClientRect();
return {x, y, width, height};
};
+ const appearance = element => {
+ const style = getComputedStyle(element);
+ return Object.fromEntries(["position", "backgroundColor", "borderTopLeftRadius", "borderTopRightRadius",
+ "borderBottomLeftRadius", "borderBottomRightRadius", "marginTop", "boxShadow"]
+ .map(key => [key, style[key]]));
+ };
bar.syncDockBarVisibility();
const initialEditor = rect(center.element);
const leftBar = document.getElementById("dockLeft");
@@ -85,24 +93,24 @@ const browserCases = async (sources, css, template) => {
open(position);
await settle();
check.ok(!hidden(element) && hidden(otherBar), "only the expanded side reveals its bar");
- check.equal(getComputedStyle(element).position, "fixed");
- check.deepEqual(rect(center.element), initialEditor, "revealing a bar does not reflow the editor");
+ check.ok(rect(center.element).width < initialEditor.width, "a temporary bar uses its normal layout space");
+ check.ok(resizes.includes(false), "bar visibility resizes the editor without saving the hidden preference");
const panelRect = dock.layout.element.getBoundingClientRect();
const barRect = element.getBoundingClientRect();
check.equal(position === "Left" ? panelRect.left : panelRect.right,
position === "Left" ? barRect.right : barRect.left, "panel stays beside the bar");
- check.ok(element.contains(document.elementFromPoint(barRect.x + barRect.width / 2, barRect.bottom - 20)),
- "the temporary bar is above the editor");
- check.equal(barRect.top, panelRect.top, "bar starts at the floating panel top");
- check.equal(barRect.bottom, panelRect.bottom, "bar ends at the floating panel bottom");
- const barStyle = getComputedStyle(element);
- const surface = document.createElement("div");
- surface.style.backgroundColor = "var(--b3-body-background)";
- document.body.append(surface);
- check.equal(barStyle.backgroundColor, getComputedStyle(surface).backgroundColor);
- surface.remove();
- check.notEqual(position === "Left" ? barStyle.borderTopLeftRadius : barStyle.borderTopRightRadius, "0px");
- check.equal(position === "Left" ? barStyle.borderTopRightRadius : barStyle.borderTopLeftRadius, "0px");
+ const temporary = {bar: rect(element), panel: rect(dock.layout.element),
+ barStyle: appearance(element), panelStyle: appearance(dock.layout.element)};
+ window.siyuan.config.uiLayout.hideDock = false;
+ bar.syncDockBarVisibility();
+ dock.showDock(true);
+ check.deepEqual({bar: rect(element), panel: rect(dock.layout.element),
+ barStyle: appearance(element), panelStyle: appearance(dock.layout.element)}, temporary,
+ "temporary bars preserve the geometry, colors and corners of normally visible bars and panels");
+ window.siyuan.config.uiLayout.hideDock = true;
+ bar.syncDockBarVisibility();
+ dock.showDock(true);
+ const expandedEditor = rect(center.element);
if (process.env.SIYUAN_DOCK_TEST_SCREENSHOTS) {
await require("electron").ipcRenderer.invoke("dock-bar-capture", position);
}
@@ -126,7 +134,7 @@ const browserCases = async (sources, css, template) => {
check.ok(entries[1].classList.contains("dock__item--active"));
check.ok(!hidden(dock.layout.element.querySelector(`[data-id="${position}two"]`)));
check.deepEqual(entries.map(item => item.dataset.entryId), order, "plugin entry identifiers and order are preserved");
- check.deepEqual(rect(center.element), initialEditor);
+ check.deepEqual(rect(center.element), expandedEditor, "switching tools preserves the occupied dock space");
entries[0].classList.add("fn__none");
bar.syncDockBarVisibility();
check.ok(hidden(entries[0]) && !hidden(element), "profile-hidden entries stay hidden during refresh");
@@ -145,10 +153,11 @@ const browserCases = async (sources, css, template) => {
menu.classList.add("fn__none");
center.element.dispatchEvent(new MouseEvent("mousemove", {bubbles: true,
- clientX: position === "Left" ? 20 : window.innerWidth - 20, clientY: barRect.top - 10}));
+ clientX: window.innerWidth / 2, clientY: 200}));
await settle();
- check.ok(hidden(element), "the area above the temporary bar does not keep the panel open");
+ check.ok(hidden(element), "leaving the dock and panel restores the hidden state");
check.equal(dock.layout.element.style.opacity, "0");
+ check.deepEqual(rect(center.element), initialEditor, "closing a temporary bar restores the editor space");
document.removeEventListener("mousemove", move);
dock.showDock();
dock.togglePanel(false);
@@ -175,9 +184,10 @@ const browserCases = async (sources, css, template) => {
docks.Left.hideDock();
check.ok(hidden(leftBar) && !hidden(rightBar), "each side closes independently");
check.equal(bottom.element.style.left, "0px");
- check.equal(bottom.element.style.right, "0px", "side overlays do not narrow the bottom panel");
+ check.equal(bottom.element.style.right, rightBar.clientWidth + "px", "bottom panel follows normally occupied side bars");
docks.Right.hideDock();
check.ok(hidden(leftBar) && hidden(rightBar), "the bottom panel alone reveals no side bars");
+ check.equal(bottom.element.style.right, "0px", "closing the side bar restores bottom panel width");
docks.Bottom.hideDock();
docks.Right.togglePin();
@@ -194,9 +204,11 @@ const browserCases = async (sources, css, template) => {
document.getElementById("toolbar").classList.add("fn__none");
document.getElementById("status").classList.add("fn__none");
await settle();
- check.equal(rightBar.getBoundingClientRect().top, right.element.getBoundingClientRect().top);
- check.equal(rightBar.getBoundingClientRect().bottom, right.element.getBoundingClientRect().bottom);
+ check.equal(rightBar.getBoundingClientRect().top,
+ rightBar.parentElement.getBoundingClientRect().top + parseFloat(getComputedStyle(rightBar).marginTop));
+ check.equal(rightBar.getBoundingClientRect().bottom, rightBar.parentElement.getBoundingClientRect().bottom);
document.body.style.setProperty("--b3-ui-dock-width", "64px");
+ docks.Right.showDock(true);
await settle();
check.equal(rightBar.clientWidth, 64);
check.equal(right.element.getBoundingClientRect().right, rightBar.getBoundingClientRect().left,
@@ -217,7 +229,6 @@ const browserCases = async (sources, css, template) => {
bar.syncDockBarVisibility();
docks.Right.showDock(true);
check.ok(!hidden(leftBar) && !hidden(rightBar));
- check.ok(!rightBar.classList.contains("dock--float"));
check.equal(rightBar.style.top, "");
check.equal(rightBar.style.zIndex, "");
docks.Right.hideDock();
@@ -258,13 +269,15 @@ if (process.versions.electron && process.type === "browser") {
for (const theme of ["daylight", "midnight"]) {
const css = readFileSync(path.join(__dirname, `../appearance/themes/${theme}/theme.css`), "utf8") + styles;
for (const width of [1200, 700]) {
- captureName = `${theme}-${width}`;
- win.setContentSize(width, 800);
- await win.loadURL("data:text/html,<html><body class='fn__flex-column'></body></html>");
- const result = await win.webContents.executeJavaScript(`(${browserCases.toString()})(${[
- sources, css, html,
- ].map(value => JSON.stringify(value)).join(",")})`);
- assert.equal(result, "Floating dock bar cases passed", `${theme}, ${width}px`);
+ for (const hideToolbar of [false, true]) {
+ captureName = `${theme}-${width}-${hideToolbar ? "hidden-toolbar" : "toolbar"}`;
+ win.setContentSize(width, 800);
+ await win.loadURL(`data:text/html,<html><body class='fn__flex-column${hideToolbar ? " body--toolbar-hide" : ""}'></body></html>`);
+ const result = await win.webContents.executeJavaScript(`(${browserCases.toString()})(${[
+ sources, css, html,
+ ].map(value => JSON.stringify(value)).join(",")})`);
+ assert.equal(result, "Floating dock bar cases passed", captureName);
+ }
}
}
console.log("Floating dock bar cases passed");
@@ -277,16 +290,16 @@ if (process.versions.electron && process.type === "browser") {
}
});
} else {
- test("floating side panels reveal hidden dock bars without changing layout or preferences", {
+ test("floating side panels temporarily reveal dock bars using their normal layout and appearance", {
skip: process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY,
- timeout: 60000,
+ timeout: 120000,
}, async () => {
const env = {...process.env};
delete env.ELECTRON_RUN_AS_NODE;
const profile = mkdtempSync(path.join(os.tmpdir(), "siyuan-dock-bar-"));
try {
const {stdout} = await require("node:util").promisify(require("node:child_process").execFile)(
- require("electron"), [__filename, profile], {env, windowsHide: true, timeout: 55000});
+ require("electron"), [__filename, profile], {env, windowsHide: true, timeout: 115000});
assert.match(stdout, /Floating dock bar cases passed/);
} finally {
assert.equal(path.dirname(path.resolve(profile)), path.resolve(os.tmpdir()));