fix(tui): switch vertical tabs sooner (#49440)

Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
This commit is contained in:
opencode-agent[bot]
2026-09-17 09:43:02 -05:00
committed by GitHub
Unverified
parent 2a132d6f50
commit a72f988c90
3 changed files with 52 additions and 15 deletions
+2 -1
View File
@@ -3,9 +3,10 @@ export const SESSION_TABS_COMPACT_WIDTH = 5
export const SESSION_TABS_COMPACT_BREAKPOINT = 12
export const SESSION_SIDEBAR_MAX_WIDTH = 72
const SESSION_CONTENT_MIN_WIDTH = 44
const SESSION_CONTENT_PREFERRED_WIDTH = 64
export function sessionTabsFitVertically(total: number, width = SESSION_SIDEBAR_WIDTH) {
return total >= width + SESSION_CONTENT_MIN_WIDTH
return total >= width + SESSION_CONTENT_PREFERRED_WIDTH
}
export function clampSessionTabsWidth(width: number, total: number) {
+43 -7
View File
@@ -430,7 +430,7 @@ test("session title generated while an untitled session is loading remains visib
}
})
test("vertical session tabs collapse to a compact rail with the terminal", async () => {
test("vertical session tabs switch to horizontal below readable content width", async () => {
await using state = await tmpdir()
await Bun.write(path.join(state.path, "test", "tui", "layout.json"), JSON.stringify({ verticalTabsWidth: 42 }))
const session = {
@@ -443,7 +443,7 @@ test("vertical session tabs collapse to a compact rail with the terminal", async
time: { created: 1, updated: 2 },
}
await using setup = await createAppFixture({
width: 100,
width: 120,
state: state.path,
config: {
animations: false,
@@ -461,15 +461,51 @@ test("vertical session tabs collapse to a compact rail with the terminal", async
await setup.ready
await setup.waitForFrame((frame) => frame.split("\n")[1].slice(0, 42).includes(session.title))
setup.resize(54, 30)
await setup.waitForFrame((frame) => frame.split("\n")[1].slice(0, 10).trim() === "⌕")
setup.resize(48, 30)
setup.resize(100, 30)
await setup.waitForFrame((frame) => frame.split("\n")[0].includes(session.title))
expect(setup.captureCharFrame()).not.toContain("⌕")
setup.resize(100, 30)
setup.resize(120, 30)
await setup.waitForFrame((frame) => frame.split("\n")[1].slice(0, 42).includes(session.title))
})
test("narrow vertical session tabs collapse to a compact rail with the terminal", async () => {
await using state = await tmpdir()
await Bun.write(path.join(state.path, "test", "tui", "layout.json"), JSON.stringify({ verticalTabsWidth: 5 }))
const session = {
id: "ses_resize",
title: "Resize fixture",
projectID: "project",
location: { directory },
cost: 0,
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
time: { created: 1, updated: 2 },
}
await using setup = await createAppFixture({
width: 80,
state: state.path,
config: {
animations: false,
tabs: { enabled: true, layout: "vertical", indicators: "status" },
session: { sidebar: "hide" },
},
args: { sessionID: session.id },
fetch: (url) => {
if (url.pathname === `/api/session/${session.id}`) return json({ data: session })
if (/^\/api\/session\/ses_resize\/(message|inbox|permission)$/.test(url.pathname))
return json({ data: [], cursor: {} })
return undefined
},
})
await setup.ready
await setup.waitForFrame((frame) => frame.split("\n")[1].slice(0, 10).trim() === "⌕")
setup.resize(68, 30)
await setup.waitForFrame((frame) => frame.split("\n")[0].includes(session.title))
expect(setup.captureCharFrame()).not.toContain("⌕")
setup.resize(80, 30)
await setup.waitForFrame((frame) => frame.split("\n")[1].slice(0, 10).trim() === "⌕")
})
test("automatic rename refreshes the displayed title before settling, even without a renamed event", async () => {
await using state = await tmpdir()
const response = Promise.withResolvers<Response>()
@@ -487,7 +523,7 @@ test("automatic rename refreshes the displayed title before settling, even witho
time: { created: 0, updated: 0 },
}
await using setup = await createAppFixture({
width: 90,
width: 110,
height: 20,
state: state.path,
config: { tabs: { enabled: true, layout: "vertical" }, session: { sidebar: "hide" } },
+7 -7
View File
@@ -7,15 +7,15 @@ import {
SESSION_TABS_COMPACT_WIDTH,
} from "../../src/ui/layout"
test("vertical tabs match the session sidebar and preserve compact content width", () => {
test("vertical tabs match the session sidebar and preserve readable content width", () => {
expect(SESSION_SIDEBAR_WIDTH).toBe(42)
expect(sessionTabsFitVertically(86)).toBe(true)
expect(sessionTabsFitVertically(85)).toBe(false)
expect(sessionTabsFitVertically(106)).toBe(true)
expect(sessionTabsFitVertically(105)).toBe(false)
})
test("vertical tabs account for a resized width", () => {
expect(sessionTabsFitVertically(104, 60)).toBe(true)
expect(sessionTabsFitVertically(103, 60)).toBe(false)
expect(sessionTabsFitVertically(124, 60)).toBe(true)
expect(sessionTabsFitVertically(123, 60)).toBe(false)
})
test("vertical tab width preserves minimum rail and content widths", () => {
@@ -26,6 +26,6 @@ test("vertical tab width preserves minimum rail and content widths", () => {
expect(clampSessionTabsWidth(100, 120)).toBe(SESSION_SIDEBAR_MAX_WIDTH)
expect(clampSessionTabsWidth(100, 100)).toBe(56)
expect(clampSessionTabsWidth(42, 54)).toBe(10)
expect(sessionTabsFitVertically(49, SESSION_TABS_COMPACT_WIDTH)).toBe(true)
expect(sessionTabsFitVertically(48, SESSION_TABS_COMPACT_WIDTH)).toBe(false)
expect(sessionTabsFitVertically(69, SESSION_TABS_COMPACT_WIDTH)).toBe(true)
expect(sessionTabsFitVertically(68, SESSION_TABS_COMPACT_WIDTH)).toBe(false)
})