From 5a9783dbf01125b586e0ea50816e011798bb120e Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Sun, 22 Nov 2026 01:51:01 +0800 Subject: [PATCH] fix(workbench): keep tool window header actions in view (#5053) Tool window titles and tabs give up width before the header actions, so Options and Hide stay at the right edge of a narrow pane. A shortened title keeps its full text on hover. When the contributed controls need more room, their strip scrolls independently while Options and Hide stay in place. --- e2e/toolWindowHeaderLayout.spec.ts | 67 +++++++++++++++++++ .../toolwindows/ToolWindows.module.css | 39 ++++++++--- src/workbench/toolwindows/ToolWindows.tsx | 16 +++-- 3 files changed, 110 insertions(+), 12 deletions(-) create mode 100644 e2e/toolWindowHeaderLayout.spec.ts diff --git a/e2e/toolWindowHeaderLayout.spec.ts b/e2e/toolWindowHeaderLayout.spec.ts new file mode 100644 index 000000000..a12b74f5a --- /dev/null +++ b/e2e/toolWindowHeaderLayout.spec.ts @@ -0,0 +1,67 @@ +import { expect, openFromTree, test } from "./fixtures"; + +test("tool window header keeps its actions visible as the Project pane narrows", async ({ workbench: page }) => { + await openFromTree(page, "build.gradle.kts"); + const project = page.locator('[data-toolwindow="project"]'); + const header = project.locator("header"); + await header.getByRole("button", { name: "Project", exact: true }).click(); + await page.getByRole("menuitemcheckbox", { name: "Project Files", exact: true }).click(); + + const title = header.getByRole("button", { name: "Project Files", exact: true }); + const options = header.getByRole("button", { name: "Options", exact: true }); + const hide = header.getByRole("button", { name: "Hide", exact: true }); + await expect(title).toHaveCSS("font-size", "13px"); + const resize = (width: number) => + page.evaluate(async (width) => { + const path = "/src/workbench/toolwindows/store.ts"; + (await import(/* @vite-ignore */ path)).setToolWindowSize("left", width); + }, width); + await resize(168); + await expect + .poll( + () => + header.evaluate((element) => { + const bounds = element.getBoundingClientRect(); + return [...element.querySelectorAll("button")].every((button) => { + const box = button.getBoundingClientRect(); + return box.width > 0 && box.left >= bounds.left && box.right <= bounds.right; + }); + }), + { message: "All header buttons fit inside the narrow Project tool window" }, + ) + .toBe(true); + expect(await title.getByText("Project Files").evaluate((el) => el.scrollWidth > el.clientWidth)).toBe(true); + await title.press("Enter"); + await expect(page.getByRole("menu", { name: "Project views" })).toBeVisible(); + await page.keyboard.press("Escape"); + + await options.press("Enter"); + await expect(page.getByRole("menu", { name: "Project options" })).toBeVisible(); + await page.keyboard.press("Escape"); + await expect(options).toBeFocused(); + + await resize(110); + const collapse = header.getByRole("button", { name: "Collapse All", exact: true }); + await collapse.focus(); + await expect + .poll(async () => { + const [pane, collapseBox, optionsBox, hideBox] = await Promise.all([ + header.boundingBox(), + collapse.boundingBox(), + options.boundingBox(), + hide.boundingBox(), + ]); + return ( + !!pane && + !!collapseBox && + !!optionsBox && + !!hideBox && + collapseBox.x >= pane.x && + collapseBox.x + collapseBox.width <= optionsBox.x && + hideBox.x + hideBox.width <= pane.x + pane.width + ); + }) + .toBe(true); + await hide.click(); + await expect(project).toBeHidden(); +}); diff --git a/src/workbench/toolwindows/ToolWindows.module.css b/src/workbench/toolwindows/ToolWindows.module.css index c39a4e832..34739fb4b 100644 --- a/src/workbench/toolwindows/ToolWindows.module.css +++ b/src/workbench/toolwindows/ToolWindows.module.css @@ -442,8 +442,8 @@ flex: none; display: flex; align-items: center; - gap: var(--space-1-5); - padding: 0 6px 0 8px; + gap: var(--space-1); + padding: 0 var(--space-2); color: var(--fg-emphasis); font-size: var(--fs-chrome); } @@ -451,7 +451,7 @@ border-bottom: 1px solid var(--border); } .title { - flex: none; + min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; @@ -461,12 +461,14 @@ padding: 0 4px; } .titleButton { - flex: none; height: 24px; + min-width: 0; display: inline-flex; align-items: center; + justify-content: flex-end; gap: var(--space-1); - padding: 0 4px; + padding: 0 0 0 var(--space-1); + overflow: hidden; border-radius: var(--radius-small); transition: background var(--dur-fast) var(--ease); } @@ -488,9 +490,6 @@ .headerContentOnly { margin-left: 0; } -.headerSpacer { - flex: 1; -} .headerActions { display: flex; align-items: center; @@ -498,6 +497,30 @@ opacity: 0; transition: opacity var(--dur) var(--ease); } +.header > .headerActions { + flex: none; + min-width: 0; + max-width: 100%; + margin-inline-start: auto; +} +.header > .headerActions:not(:first-child) { + max-width: calc(100% - var(--space-4) - var(--space-1)); +} +.headerContributedActions { + display: flex; + align-items: center; + gap: var(--space-0-5); + min-width: 0; + overflow-x: auto; + overflow-y: hidden; + scrollbar-width: none; +} +.headerContributedActions:empty { + display: none; +} +.headerContributedActions::-webkit-scrollbar { + display: none; +} .window:hover .headerActions, .window:focus-within .headerActions, .headerActions:has([aria-expanded="true"]) { diff --git a/src/workbench/toolwindows/ToolWindows.tsx b/src/workbench/toolwindows/ToolWindows.tsx index a52a2ce9d..c8611788f 100644 --- a/src/workbench/toolwindows/ToolWindows.tsx +++ b/src/workbench/toolwindows/ToolWindows.tsx @@ -712,7 +712,11 @@ function ToolWindowActionsBar({ tw, className }: { tw: ToolWindowContribution; c return ( <>
- {Actions && } + {Actions && ( +
+ +
+ )} setTitleOpen((v) => !v)} > - {titleMenu ? tx(titleMenu.label) : toolWindowTitle(tw)} + {titleLabel} ) : ( - {toolWindowTitle(tw)} + + {windowTitle} + )} {children &&
{children}
} -
{actions && } );