fix(terminal): give scrollback search a compact layout (#5264)

Size the floating terminal find bar to its controls. Keep the match count beside the previous and next buttons, and move the controls below the query in narrow docks so the full first row is available for typing.
This commit is contained in:
l0ng-ai
2026-11-23 09:14:26 +08:00
committed by GitHub
parent dd0eeeae29
commit e0a97e32f7
3 changed files with 108 additions and 61 deletions
+22 -4
View File
@@ -71,7 +71,15 @@ for (const { width, split } of [{ width: 220 }, { width: 280 }, { width: 520 },
const search = terminal.getByRole("search", { name: "Find in terminal" });
const input = search.getByRole("textbox", { name: "Find in terminal" });
await input.fill("alpha");
await expect(search.locator("[aria-live=polite]")).toHaveText(/\d+\/3/);
const count = search.locator("[aria-live=polite]");
await expect(count).toHaveText(/\d+\/3/);
await expect(count).toHaveCSS("font-size", "13px");
const match = await count.textContent();
// The incremental search can report after the first Enter; retry until Enter moves on.
await expect(async () => {
await input.press("Enter");
await expect(count).not.toHaveText(match!, { timeout: 1000 });
}).toPass();
if (process.env.OPENIDEA_TERMINAL_SHOTS)
await terminal.screenshot({
path: `${process.env.OPENIDEA_TERMINAL_SHOTS}/terminal-${width}${split ? "-split" : ""}.png`,
@@ -83,9 +91,19 @@ for (const { width, split } of [{ width: 220 }, { width: 280 }, { width: 520 },
expect(rect.x).toBeGreaterThanOrEqual(bounds.x);
expect(rect.x + rect.width).toBeLessThanOrEqual(bounds.x + bounds.width + 1);
}
expect((await input.boundingBox())!.width).toBeGreaterThan(40);
const matchCase = search.getByRole("button", { name: "Match Case", exact: true });
const inputBox = (await input.boundingBox())!;
if (width <= 280 || split) {
expect(inputBox.width).toBeGreaterThan(bounds.width * 0.62);
expect((await matchCase.boundingBox())!.y).toBeGreaterThan(inputBox.y + inputBox.height);
} else {
expect(inputBox.width).toBeGreaterThan(80);
}
const countBox = (await count.boundingBox())!;
const previousBox = (await search.getByRole("button", { name: "Previous Occurrence", exact: true }).boundingBox())!;
expect(previousBox.x - countBox.x - countBox.width).toBeLessThanOrEqual(4);
expect(countBox.y + countBox.height / 2).toBeCloseTo(previousBox.y + previousBox.height / 2, 0);
await matchCase.focus();
await page.keyboard.press("Enter");
await expect(matchCase).toHaveAttribute("aria-pressed", "true");
@@ -130,7 +148,7 @@ test("wide terminal search leaves the grid in place and avoids covering the acti
const top = (await search.boundingBox())!;
expect(top.y).toBeCloseTo(before.y, 0);
expect(top.x + top.width).toBeCloseTo(before.x + before.width, 0);
expect(top.width).toBeLessThan(before.width);
expect(top.width).toBeLessThan(420);
await input.fill("right-edge");
await expect(search.locator("[aria-live=polite]")).toHaveText("1/1");
+57 -46
View File
@@ -166,53 +166,64 @@ export function TerminalFindBar({ sessionKey }: { sessionKey: string | null }) {
placeholder="Find in terminal"
aria-label="Find in terminal"
invalid={none}
toggles={[
{
id: "case",
icon: "case",
title: "Match Case",
shortcut: formatBinding("Alt+C"),
pressed: options.caseSensitive,
onToggle: () => toggle("caseSensitive"),
},
{
id: "word",
icon: "word",
title: "Words",
shortcut: formatBinding("Alt+W"),
pressed: options.wholeWord,
onToggle: () => toggle("wholeWord"),
},
{
id: "regex",
icon: "regex",
title: "Regex",
shortcut: formatBinding("Alt+X"),
pressed: options.regex,
onToggle: () => toggle("regex"),
},
]}
/>
<span className={clsx(styles.findCount, none && styles.findCountNone)} aria-live="polite">
{counter}
</span>
<IconButton
icon="arrow-up"
title="Previous Occurrence"
shortcut={formatBinding("Shift+Enter")}
size="small"
disabled={!query || !result?.count}
onClick={() => find("previous")}
/>
<IconButton
icon="arrow-down"
title="Next Occurrence"
shortcut="↵"
size="small"
disabled={!query || !result?.count}
onClick={() => find("next")}
/>
<IconButton icon="close" title="Close" shortcut="⎋" size="small" onClick={closeTerminalFind} />
<div className={styles.findControls}>
<div className={styles.findOptions}>
<IconButton
icon="case"
title="Match Case"
shortcut={formatBinding("Alt+C")}
pressed={options.caseSensitive}
size="small"
onClick={() => toggle("caseSensitive")}
/>
<IconButton
icon="word"
title="Words"
shortcut={formatBinding("Alt+W")}
pressed={options.wholeWord}
size="small"
onClick={() => toggle("wholeWord")}
/>
<IconButton
icon="regex"
title="Regex"
shortcut={formatBinding("Alt+X")}
pressed={options.regex}
size="small"
onClick={() => toggle("regex")}
/>
</div>
<div className={styles.findActions}>
<span className={clsx(styles.findCount, none && styles.findCountNone)} aria-live="polite">
{counter}
</span>
<IconButton
icon="arrow-up"
title="Previous Occurrence"
shortcut={formatBinding("Shift+Enter")}
size="small"
disabled={!query || !result?.count}
onClick={() => find("previous")}
/>
<IconButton
icon="arrow-down"
title="Next Occurrence"
shortcut="↵"
size="small"
disabled={!query || !result?.count}
onClick={() => find("next")}
/>
</div>
<IconButton
className={styles.findClose}
icon="close"
title="Close"
shortcut="⎋"
size="small"
onClick={closeTerminalFind}
/>
</div>
</div>
);
}
+29 -11
View File
@@ -163,21 +163,33 @@
display: flex;
align-items: center;
gap: var(--space-1);
padding: 4px 8px;
padding: var(--space-1) var(--space-2);
background: var(--bg-elev);
border-bottom: 1px solid var(--border);
font-size: var(--fs-ui);
}
.findField {
flex: 1;
min-width: 160px;
width: calc(14ch + 2 * var(--h-control-small) + var(--space-4));
min-width: 0;
}
.findControls,
.findOptions,
.findActions {
display: flex;
align-items: center;
gap: var(--space-0-5);
}
.findControls {
gap: var(--space-1);
}
.findCount {
font-size: var(--fs-small);
font-size: var(--fs-ui);
font-variant-numeric: tabular-nums;
color: var(--fg-subtle);
padding: 0 6px;
min-inline-size: 7ch;
padding-inline: var(--space-1);
text-align: center;
white-space: nowrap;
min-width: 56px;
}
.findCountNone {
color: var(--danger);
@@ -188,7 +200,8 @@
top: 0;
right: 0;
z-index: 6;
width: 500px;
width: max-content;
max-width: 100%;
border-left: 1px solid var(--border);
}
.find[data-match-covered] {
@@ -201,11 +214,16 @@
@container terminal-output (max-width: 360px) {
.find {
display: grid;
grid-template-columns: minmax(0, 1fr) repeat(3, var(--h-control-small));
flex-direction: column;
align-items: stretch;
}
.findField {
grid-column: 1 / -1;
min-width: 0;
width: 100%;
}
.findControls {
flex-wrap: wrap;
}
.findClose {
margin-inline-start: auto;
}
}