fix(tui): preserve tab context on home and close (#39421)

This commit is contained in:
Kit Langton 2026-07-28 21:03:17 -04:00 committed by GitHub
commit 1c8175a61a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 56 additions and 9 deletions

View file

@ -75,6 +75,15 @@ describe("session tabs", () => {
expect(moveSessionTabHistory(history, tabs, undefined, -1).sessionID).toBe("b")
})
test("returns to the previous selected open tab after closing the active tab", () => {
const tabs = ["a", "b", "c"].map((sessionID) => ({ sessionID }))
const history = ["a", "c"].reduce(recordSessionTabHistory, { entries: [], index: -1 })
const closed = closeSessionTab(tabs, "b")
const current = recordSessionTabHistory(history, "b")
expect(moveSessionTabHistory(current, closed.tabs, "b", -1).sessionID).toBe("c")
})
test("reveals completion activity only after session work becomes idle", () => {
expect(sessionTabComplete("activity", true)).toBe(false)
expect(sessionTabComplete("activity", false)).toBe(true)
@ -90,6 +99,24 @@ describe("session tabs", () => {
expect(layout.widths.reduce((total, width) => total + width, 0)).toBe(76)
})
test("does not reserve an active tab slot on the new session page", () => {
const tabs = ["a", "b", "c", "d", "e"].map((sessionID) => ({ sessionID }))
const layout = adaptiveSessionTabLayout(tabs, "dummy", 40)
expect(layout.tabs).toEqual(tabs)
expect(layout.widths).toEqual([8, 8, 8, 8, 8])
expect(layout.widths.reduce((total, width) => total + width, 0)).toBe(layout.total)
})
test("keeps the visible tab window stable on the new session page", () => {
const tabs = Array.from({ length: 10 }, (_, index) => ({ sessionID: String(index) }))
const selected = adaptiveSessionTabLayout(tabs, "7", 70)
const home = adaptiveSessionTabLayout(tabs, undefined, 70, selected.start)
expect(selected.start).toBeGreaterThan(0)
expect(home.start).toBe(selected.start)
})
test("only swaps old and new active width inside a sticky window", () => {
const tabs = ["a", "b", "c", "d", "e", "f", "g"].map((sessionID) => ({ sessionID }))
const before = adaptiveSessionTabLayout(tabs, "c", 76)