mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
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.
This commit is contained in:
@@ -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();
|
||||
});
|
||||
@@ -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"]) {
|
||||
|
||||
@@ -712,7 +712,11 @@ function ToolWindowActionsBar({ tw, className }: { tw: ToolWindowContribution; c
|
||||
return (
|
||||
<>
|
||||
<div className={clsx(styles.headerActions, className)}>
|
||||
{Actions && <Actions id={tw.id} />}
|
||||
{Actions && (
|
||||
<div className={styles.headerContributedActions}>
|
||||
<Actions id={tw.id} />
|
||||
</div>
|
||||
)}
|
||||
<IconButton
|
||||
ref={moreRef}
|
||||
icon="more"
|
||||
@@ -766,6 +770,8 @@ function HeaderRow({
|
||||
const useTitleMenu = tw.titleMenu ?? noTitleMenu;
|
||||
const titleMenu = useTitleMenu(tw.id);
|
||||
const titleItems = titleMenu?.items ?? (tw.plainTitle ? [] : own);
|
||||
const windowTitle = toolWindowTitle(tw);
|
||||
const titleLabel = titleMenu ? tx(titleMenu.label) : windowTitle;
|
||||
|
||||
return (
|
||||
<header
|
||||
@@ -789,11 +795,12 @@ function HeaderRow({
|
||||
ref={titleRef}
|
||||
type="button"
|
||||
className={styles.titleButton}
|
||||
title={titleLabel}
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={titleOpen}
|
||||
onClick={() => setTitleOpen((v) => !v)}
|
||||
>
|
||||
<span className={styles.title}>{titleMenu ? tx(titleMenu.label) : toolWindowTitle(tw)}</span>
|
||||
<span className={styles.title}>{titleLabel}</span>
|
||||
<Icon name="chevron-down" size={12} className={styles.titleChevron} />
|
||||
</button>
|
||||
<Menu
|
||||
@@ -805,10 +812,11 @@ function HeaderRow({
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<span className={clsx(styles.title, styles.titlePlain)}>{toolWindowTitle(tw)}</span>
|
||||
<span className={clsx(styles.title, styles.titlePlain)} title={windowTitle}>
|
||||
{windowTitle}
|
||||
</span>
|
||||
)}
|
||||
{children && <div className={clsx(styles.headerContent, !showTitle && styles.headerContentOnly)}>{children}</div>}
|
||||
<div className={styles.headerSpacer} />
|
||||
{actions && <ToolWindowActionsBar tw={tw} />}
|
||||
</header>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user