diff --git a/e2e/terminalSessionTabsLayout.spec.ts b/e2e/terminalSessionTabsLayout.spec.ts new file mode 100644 index 000000000..25cbd5a59 --- /dev/null +++ b/e2e/terminalSessionTabsLayout.spec.ts @@ -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); +}); diff --git a/src/features/terminal/TerminalView.tsx b/src/features/terminal/TerminalView.tsx index 3797ce7d2..a20993a3a 100644 --- a/src/features/terminal/TerminalView.tsx +++ b/src/features/terminal/TerminalView.tsx @@ -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[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 }) { > 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.