Skip to content

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

:bug: Prevent inactive dock panels from retaining width https://github.com/siyuan-note/siyuan/issues/19085

Danield8cd560ab430
diff --git a/app/src/layout/dock/index.ts b/app/src/layout/dock/index.ts
index 35a5b0264f..694958b344 100644
--- a/app/src/layout/dock/index.ts
+++ b/app/src/layout/dock/index.ts
@@ -494,6 +494,9 @@ export class Dock {
}
}
this.layout.element.classList.toggle("layout--float", this.isFloating());
+ if (!hasActive && !this.isFloating()) {
+ this.layout.element.style[this.position === "Bottom" ? "height" : "width"] = "0px";
+ }
resizeTabs(isSaveLayout);
setTabPosition(true);
}
@@ -1125,7 +1128,7 @@ export class Dock {
return max;
}
- private hasActive() {
+ public hasActive() {
return Boolean(this.elements[0].querySelector(".dock__item--active") ||
this.elements[1].querySelector(".dock__item--active"));
}
diff --git a/app/src/layout/dock/responsive.ts b/app/src/layout/dock/responsive.ts
index 9170bef0e1..6c36f7e42a 100644
--- a/app/src/layout/dock/responsive.ts
+++ b/app/src/layout/dock/responsive.ts
@@ -3,6 +3,7 @@ import {
getCenterMinimumSize,
type ICenterMinimumLayoutNode,
resolveDockResponsiveLayout,
+ resolveDockResponsiveWidth,
} from "./responsiveLayout";
import {runWithoutDockTransitions} from "./responsiveTransition";
@@ -48,30 +49,37 @@ const updateResponsiveWidth = (
dock: typeof window.siyuan.layout.leftDock,
preferredSize: number,
fixedSize: number,
+ active: boolean,
) => {
const element = dock.layout.element;
const hasResponsiveWidth = Boolean(element.style.maxWidth ||
element.hasAttribute(Constants.ATTRIBUTE_DOCK_WIDTH));
- const shouldConstrain = !dock.isResponsiveFloating() && fixedSize > 0 && fixedSize < preferredSize;
- if (!shouldConstrain) {
- if (!hasResponsiveWidth) {
- return;
- }
+ const result = resolveDockResponsiveWidth({
+ active,
+ preferredSize,
+ fixedSize,
+ floating: dock.isResponsiveFloating(),
+ constrained: hasResponsiveWidth,
+ });
+ if (result.clearConstraint) {
element.style.maxWidth = "";
element.removeAttribute(Constants.ATTRIBUTE_DOCK_WIDTH);
- const preferredWidth = preferredSize + "px";
- if (preferredSize > 0 && element.style.width !== preferredWidth) {
- element.style.width = preferredWidth;
- }
- return;
}
- const preferredWidth = preferredSize.toString();
- const maximumWidth = fixedSize + "px";
- if (element.getAttribute(Constants.ATTRIBUTE_DOCK_WIDTH) !== preferredWidth) {
- element.setAttribute(Constants.ATTRIBUTE_DOCK_WIDTH, preferredWidth);
+ if (typeof result.width === "number") {
+ const width = result.width + "px";
+ if (element.style.width !== width) {
+ element.style.width = width;
+ }
}
- if (element.style.maxWidth !== maximumWidth) {
- element.style.maxWidth = maximumWidth;
+ if (typeof result.maximumWidth === "number") {
+ const preferredWidth = preferredSize.toString();
+ const maximumWidth = result.maximumWidth + "px";
+ if (element.getAttribute(Constants.ATTRIBUTE_DOCK_WIDTH) !== preferredWidth) {
+ element.setAttribute(Constants.ATTRIBUTE_DOCK_WIDTH, preferredWidth);
+ }
+ if (element.style.maxWidth !== maximumWidth) {
+ element.style.maxWidth = maximumWidth;
+ }
}
};
@@ -104,6 +112,8 @@ export const reconcileResponsiveDockLayout = () => {
));
const leftPreferredSize = leftDock.getResponsivePreferredSize();
const rightPreferredSize = rightDock.getResponsivePreferredSize();
+ const leftActive = leftDock.hasActive();
+ const rightActive = rightDock.hasActive();
const leftParticipating = leftDock.pin && leftDock.isPanelVisible();
const rightParticipating = rightDock.pin && rightDock.isPanelVisible();
const preferredOccupiedSize = centerMinimumSize +
@@ -154,8 +164,8 @@ export const reconcileResponsiveDockLayout = () => {
leftDock.setResponsiveFloating(true, leftPreferredSize);
}
- updateResponsiveWidth(leftDock, leftPreferredSize, result.left.fixedSize);
- updateResponsiveWidth(rightDock, rightPreferredSize, result.right.fixedSize);
+ updateResponsiveWidth(leftDock, leftPreferredSize, result.left.fixedSize, leftActive);
+ updateResponsiveWidth(rightDock, rightPreferredSize, result.right.fixedSize, rightActive);
if (centerLayout.element.clientWidth !== centerSizeBefore && hasCenterMaximumWidth(centerLayout)) {
leftDock.adjustResponsiveCenterLayout();
}
diff --git a/app/src/layout/dock/responsiveLayout.test.ts b/app/src/layout/dock/responsiveLayout.test.ts
index cb5e91d142..466ea66c98 100644
--- a/app/src/layout/dock/responsiveLayout.test.ts
+++ b/app/src/layout/dock/responsiveLayout.test.ts
@@ -5,6 +5,7 @@ import {
IDockResponsiveLayoutInput,
IDockResponsiveSideInput,
resolveDockResponsiveLayout,
+ resolveDockResponsiveWidth,
} from "./responsiveLayout";
const createSide = (overrides: Partial<IDockResponsiveSideInput> = {}): IDockResponsiveSideInput => ({
@@ -136,6 +137,57 @@ describe("responsive dock layout", () => {
});
});
+describe("responsive dock width", () => {
+ it("clears stale constraints and keeps an inactive dock collapsed", () => {
+ assert.deepEqual(resolveDockResponsiveWidth({
+ active: false,
+ preferredSize: 580,
+ fixedSize: 0,
+ floating: false,
+ constrained: true,
+ }), {
+ clearConstraint: true,
+ width: 0,
+ });
+ });
+
+ it("restores the preferred width for a collapsed panel that still has active tools", () => {
+ assert.deepEqual(resolveDockResponsiveWidth({
+ active: true,
+ preferredSize: 580,
+ fixedSize: 0,
+ floating: false,
+ constrained: true,
+ }), {
+ clearConstraint: true,
+ width: 580,
+ });
+ });
+
+ it("applies the allocated maximum width to an active fixed dock", () => {
+ assert.deepEqual(resolveDockResponsiveWidth({
+ active: true,
+ preferredSize: 580,
+ fixedSize: 420,
+ floating: false,
+ constrained: false,
+ }), {
+ clearConstraint: false,
+ maximumWidth: 420,
+ });
+ });
+
+ it("leaves an unconstrained active dock unchanged", () => {
+ assert.deepEqual(resolveDockResponsiveWidth({
+ active: true,
+ preferredSize: 580,
+ fixedSize: 580,
+ floating: false,
+ constrained: false,
+ }), {clearConstraint: false});
+ });
+});
+
describe("center minimum size", () => {
const pane = () => ({});
diff --git a/app/src/layout/dock/responsiveLayout.ts b/app/src/layout/dock/responsiveLayout.ts
index 4fd6ca85d5..e2b621b0ee 100644
--- a/app/src/layout/dock/responsiveLayout.ts
+++ b/app/src/layout/dock/responsiveLayout.ts
@@ -25,6 +25,20 @@ export interface IDockResponsiveLayoutResult {
right: IDockResponsiveSideResult;
}
+export interface IDockResponsiveWidthInput {
+ active: boolean;
+ preferredSize: number;
+ fixedSize: number;
+ floating: boolean;
+ constrained: boolean;
+}
+
+export interface IDockResponsiveWidthResult {
+ clearConstraint: boolean;
+ width?: number;
+ maximumWidth?: number;
+}
+
export interface ICenterMinimumLayoutNode {
inactive?: boolean;
direction?: "lr" | "tb";
@@ -39,6 +53,31 @@ type SideName = "left" | "right";
const normalizeSize = (size: number) => Number.isFinite(size) ? Math.max(0, size) : 0;
+export const resolveDockResponsiveWidth = (input: IDockResponsiveWidthInput): IDockResponsiveWidthResult => {
+ if (!input.active) {
+ return {
+ clearConstraint: true,
+ width: 0,
+ };
+ }
+
+ const preferredSize = normalizeSize(input.preferredSize);
+ const fixedSize = normalizeSize(input.fixedSize);
+ if (!input.floating && fixedSize > 0 && fixedSize < preferredSize) {
+ return {
+ clearConstraint: false,
+ maximumWidth: fixedSize,
+ };
+ }
+ if (input.constrained) {
+ return {
+ clearConstraint: true,
+ width: preferredSize,
+ };
+ }
+ return {clearConstraint: false};
+};
+
const normalizeSide = (side: IDockResponsiveSideInput): INormalizedSide => {
const preferredSize = normalizeSize(side.preferredSize);
const minimumSize = Math.min(normalizeSize(side.minimumSize), preferredSize);