mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
fix(terminal): keep the selected session tab visible in narrow panes (#5017)
A long terminal session name could take more space than its tab strip and push the close button out of view. Each tab now fits the available width, with an ellipsis for long labels and the full name on hover. New Tab and the terminal options sit next to the strip, and the tab picker handles sessions that overflow.
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
import type { Locator, Page } from "@playwright/test";
|
||||
import { expect, stubDesktop, test } from "./fixtures";
|
||||
|
||||
const longName = "Production logs — inventory reconciliation and overnight deployment checks";
|
||||
|
||||
async function openTerminal(page: Page, width: number) {
|
||||
await stubDesktop(page);
|
||||
await page.evaluate(async (width) => {
|
||||
const handlers = window.__ipc.handlers;
|
||||
let id = 0;
|
||||
handlers.term_default_shell = () => "/bin/zsh";
|
||||
handlers.term_available_shells = () => ["/bin/zsh"];
|
||||
handlers.term_spawn = () => ({ id: ++id, title: "zsh", pid: id });
|
||||
handlers.term_resize = () => null;
|
||||
handlers.term_kill = () => null;
|
||||
const path = "/src/workbench/toolwindows/store.ts";
|
||||
const layout = await import(path);
|
||||
layout.moveToolWindow("terminal", "right");
|
||||
layout.setToolWindowSize("right", width);
|
||||
layout.showToolWindow("terminal", true);
|
||||
}, width);
|
||||
return page.getByRole("region", { name: "Terminal", exact: true });
|
||||
}
|
||||
|
||||
async function renameTerminal(tab: Locator, name: string) {
|
||||
await tab.dblclick();
|
||||
const input = tab.page().getByRole("textbox", { name: "Tab name" });
|
||||
await input.fill(name);
|
||||
await input.press("Enter");
|
||||
}
|
||||
|
||||
async function expectSelectedTabToFit(strip: Locator) {
|
||||
const selected = strip.getByRole("tab", { selected: true });
|
||||
await expect(selected).toBeVisible();
|
||||
await expect
|
||||
.poll(() =>
|
||||
selected.evaluate((tab) => {
|
||||
const clip = tab.closest('[role="tablist"]')!.getBoundingClientRect();
|
||||
const slot = tab.parentElement!.getBoundingClientRect();
|
||||
return slot.left >= clip.left - 1 && slot.right <= clip.right + 1;
|
||||
}),
|
||||
)
|
||||
.toBe(true);
|
||||
}
|
||||
|
||||
test("a narrow terminal panel keeps the selected tab's close button in view", async ({ workbench: page }) => {
|
||||
const terminal = await openTerminal(page, 220);
|
||||
const strip = terminal.getByRole("tablist", { name: "Terminal sessions" });
|
||||
await renameTerminal(strip.getByRole("tab", { name: "Local", exact: true }), longName);
|
||||
const selected = strip.getByRole("tab", { name: longName, selected: true });
|
||||
await expect(selected).toBeVisible();
|
||||
await expectSelectedTabToFit(strip);
|
||||
await expect
|
||||
.poll(() =>
|
||||
selected.getByText(longName, { exact: true }).evaluate((label) => label.scrollWidth > label.clientWidth),
|
||||
)
|
||||
.toBe(true);
|
||||
await expect(selected).toHaveAttribute("data-tooltip", new RegExp(longName));
|
||||
await expect(terminal.getByRole("button", { name: "Show Hidden Tabs" })).toBeHidden();
|
||||
await expect(terminal.getByRole("button", { name: "New Tab", exact: true })).toBeVisible();
|
||||
await terminal.getByRole("button", { name: "More Terminal Options" }).click();
|
||||
await expect(page.getByRole("menuitem", { name: /^New Terminal Tab/ })).toBeVisible();
|
||||
await page.keyboard.press("Escape");
|
||||
await strip.getByRole("button", { name: "Close Tab", exact: true }).click();
|
||||
await expect(terminal).toBeHidden();
|
||||
});
|
||||
|
||||
test("terminal split tabs fit when sessions overflow and switch through the menu", async ({ workbench: page }) => {
|
||||
const terminal = await openTerminal(page, 520);
|
||||
const strips = terminal.getByRole("tablist", { name: "Terminal sessions" });
|
||||
await strips.getByRole("tab", { name: "Local", exact: true }).click({ button: "right" });
|
||||
await page.getByRole("menuitem", { name: /^Split Right/ }).click();
|
||||
await expect(strips).toHaveCount(2);
|
||||
const header = terminal.locator("header").nth(1);
|
||||
const strip = strips.nth(1);
|
||||
await header.getByRole("button", { name: "New Tab", exact: true }).click();
|
||||
await renameTerminal(strip.getByRole("tab", { selected: true }), longName);
|
||||
await expect(strip.getByRole("tab", { name: longName, selected: true })).toBeVisible();
|
||||
await expectSelectedTabToFit(strip);
|
||||
const hidden = header.getByRole("button", { name: "Show Hidden Tabs" });
|
||||
await hidden.click();
|
||||
await page.getByRole("menuitem", { name: "Local (2)", exact: true }).click();
|
||||
await expect(strip.getByRole("tab", { name: "Local (2)", selected: true })).toBeVisible();
|
||||
await expectSelectedTabToFit(strip);
|
||||
await expect(header.getByRole("button", { name: "More Terminal Options" })).toBeVisible();
|
||||
await hidden.click();
|
||||
await page.getByRole("menuitem", { name: longName, exact: true }).click();
|
||||
await expect(strip.getByRole("tab", { name: longName, selected: true })).toBeVisible();
|
||||
await expectSelectedTabToFit(strip);
|
||||
});
|
||||
@@ -58,11 +58,11 @@ const TAB_PREFIX = "openidea-terminal";
|
||||
*/
|
||||
const TAB_MIME = "application/x-openidea-terminal-tab";
|
||||
|
||||
/** Full title when the label is trimmed, then the working directory. */
|
||||
/** Session title and working directory, even when available space trims the label. */
|
||||
function tabTooltip(tab: TerminalTab, sessions: Parameters<typeof tabTitle>[1]): string | undefined {
|
||||
const full = tabFullTitle(tab, sessions);
|
||||
const cwd = sessions?.[tab.session]?.cwd;
|
||||
if (full === tabTitle(tab, sessions)) return cwd;
|
||||
if (full === tab.name) return cwd;
|
||||
return cwd ? `${full}\n${cwd}` : full;
|
||||
}
|
||||
|
||||
@@ -457,6 +457,7 @@ function GroupTabs({ group }: { group: string }) {
|
||||
>
|
||||
<Tabs
|
||||
variant="compact"
|
||||
layout="fit"
|
||||
className={styles.tabStrip}
|
||||
aria-label="Terminal sessions"
|
||||
items={items}
|
||||
|
||||
+11
-3
@@ -172,7 +172,13 @@
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
/* Tabs that don't fit: squeezed (labels ellipsized) or wrapped into rows. */
|
||||
/* A scrolling tab can shorten its label to keep the close button in view. */
|
||||
.fit .tab {
|
||||
min-width: 0;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
/* Squeezed tabs share the available width. */
|
||||
.squeeze .scroller {
|
||||
flex: 0 1 auto;
|
||||
}
|
||||
@@ -187,12 +193,14 @@
|
||||
.squeeze .closeSlot {
|
||||
flex: none;
|
||||
}
|
||||
.squeeze .tabButton {
|
||||
.squeeze .tabButton,
|
||||
.fit .tabButton {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.squeeze .tabLabel {
|
||||
.squeeze .tabLabel,
|
||||
.fit .tabLabel {
|
||||
min-width: 0;
|
||||
}
|
||||
.wrap {
|
||||
|
||||
+6
-3
@@ -150,8 +150,8 @@ export interface TabsProps {
|
||||
focusContent?: () => boolean;
|
||||
/** Enables drag & drop reordering (and moving between strips of the same type). */
|
||||
dnd?: TabsDnd;
|
||||
/** Tabs that don't fit: `scroll` the strip (default), `squeeze` them, or `wrap` into rows. */
|
||||
layout?: "scroll" | "squeeze" | "wrap";
|
||||
/** `fit` keeps each tab within the scrolling strip. `squeeze` shrinks tabs together and `wrap` adds rows. */
|
||||
layout?: "scroll" | "fit" | "squeeze" | "wrap";
|
||||
/** For editor strips, show only tabs clipped by the strip in the overflow popup. */
|
||||
hiddenTabsOnly?: boolean;
|
||||
/** Side of the label the close button sits on. */
|
||||
@@ -290,6 +290,7 @@ export function Tabs({
|
||||
};
|
||||
}, [tabIds]);
|
||||
|
||||
const observedTabs = layout === "fit" ? tabIds : null;
|
||||
useLayoutEffect(() => {
|
||||
const el = scrollRef.current;
|
||||
if (!el) return;
|
||||
@@ -306,8 +307,10 @@ export function Tabs({
|
||||
if (typeof ResizeObserver === "undefined") return;
|
||||
const ro = new ResizeObserver(measure);
|
||||
ro.observe(el);
|
||||
// A renamed tab can move or resize the selected slot without resizing the strip.
|
||||
if (observedTabs) for (const tab of el.children) ro.observe(tab);
|
||||
return () => ro.disconnect();
|
||||
}, [items.length, revealTab, vertical, hiddenTabsOnly, closeMenu]);
|
||||
}, [items.length, observedTabs, revealTab, vertical, hiddenTabsOnly, closeMenu]);
|
||||
|
||||
useEffect(() => {
|
||||
// The whole tab (label + close button) into view, without scrolling any outer container.
|
||||
|
||||
Reference in New Issue
Block a user