diff --git a/apps/web/src/components/WorkspacePanel.test.ts b/apps/web/src/components/WorkspacePanel.test.ts index d5d8fc88a..0fa504d59 100644 --- a/apps/web/src/components/WorkspacePanel.test.ts +++ b/apps/web/src/components/WorkspacePanel.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { resolveWorkspaceLayoutMode } from "./WorkspacePanel"; +import { resolveWorkspaceLayoutMode, resolveWorkspacePanelDirection } from "./WorkspacePanel"; describe("resolveWorkspaceLayoutMode", () => { it("stacks the tree above the editor in narrower panels", () => { @@ -12,3 +12,32 @@ describe("resolveWorkspaceLayoutMode", () => { expect(resolveWorkspaceLayoutMode(960)).toBe("split"); }); }); + +describe("resolveWorkspacePanelDirection", () => { + it("keeps split workspaces side by side while the tree is open", () => { + expect( + resolveWorkspacePanelDirection({ + layoutMode: "split", + treeCollapsed: false, + }), + ).toBe("flex-row"); + }); + + it("collapses the tree vertically even in split workspaces", () => { + expect( + resolveWorkspacePanelDirection({ + layoutMode: "split", + treeCollapsed: true, + }), + ).toBe("flex-col"); + }); + + it("stacks narrow workspaces vertically", () => { + expect( + resolveWorkspacePanelDirection({ + layoutMode: "stacked", + treeCollapsed: false, + }), + ).toBe("flex-col"); + }); +}); diff --git a/apps/web/src/components/WorkspacePanel.tsx b/apps/web/src/components/WorkspacePanel.tsx index 300628c11..d1da107f7 100644 --- a/apps/web/src/components/WorkspacePanel.tsx +++ b/apps/web/src/components/WorkspacePanel.tsx @@ -3,6 +3,7 @@ import { memo, type ReactNode, useEffect, useRef, useState } from "react"; import { cn } from "~/lib/utils"; export type WorkspaceLayoutMode = "stacked" | "split"; +export type WorkspacePanelDirection = "flex-col" | "flex-row"; const WORKSPACE_SPLIT_MIN_WIDTH_PX = 600; @@ -10,6 +11,17 @@ export function resolveWorkspaceLayoutMode(width: number): WorkspaceLayoutMode { return width >= WORKSPACE_SPLIT_MIN_WIDTH_PX ? "split" : "stacked"; } +export function resolveWorkspacePanelDirection(input: { + layoutMode: WorkspaceLayoutMode; + treeCollapsed: boolean; +}): WorkspacePanelDirection { + if (input.layoutMode === "split" && !input.treeCollapsed) { + return "flex-row"; + } + + return "flex-col"; +} + function basenameOfPath(pathValue: string): string { const normalizedPath = pathValue.replace(/\/+$/, ""); const segments = normalizedPath.split("/"); @@ -53,10 +65,11 @@ export const WorkspacePanel = memo(function WorkspacePanel(props: { }, []); const [treeCollapsed, setTreeCollapsed] = useState(false); + const panelDirection = resolveWorkspacePanelDirection({ layoutMode, treeCollapsed }); return (
-
+
{props.cwd ? (