fix: return to Orca landing screen after closing last terminal (#677)

This commit is contained in:
Brennan Benson
2026-04-15 16:08:08 -07:00
committed by GitHub
parent ae54be0450
commit e73f831490
2 changed files with 94 additions and 1 deletions
@@ -795,6 +795,62 @@ describe('setActiveWorktree', () => {
expect(replacement.title).toBe('Terminal 1')
})
it('returns to the landing state when closing the last terminal tab in the active worktree', () => {
const store = createTestStore()
const wt = 'repo1::/path/wt1'
const groupId = 'group-1'
const tabId = 'tab-1'
const unifiedTabId = 'unified-tab-1'
seedStore(store, {
worktreesByRepo: {
repo1: [makeWorktree({ id: wt, repoId: 'repo1', path: '/path/wt1' })]
},
activeWorktreeId: wt,
activeTabId: tabId,
activeTabType: 'terminal',
activeTabIdByWorktree: { [wt]: tabId },
activeTabTypeByWorktree: { [wt]: 'terminal' },
tabsByWorktree: {
[wt]: [makeTab({ id: tabId, worktreeId: wt })]
},
unifiedTabsByWorktree: {
[wt]: [
makeUnifiedTab({
id: unifiedTabId,
entityId: tabId,
worktreeId: wt,
groupId,
contentType: 'terminal',
label: 'Terminal 1'
})
]
},
groupsByWorktree: {
[wt]: [
makeTabGroup({
id: groupId,
worktreeId: wt,
activeTabId: unifiedTabId,
tabOrder: [unifiedTabId]
})
]
},
activeGroupIdByWorktree: { [wt]: groupId },
layoutByWorktree: {
[wt]: { type: 'leaf', groupId }
}
})
store.getState().closeTab(tabId)
const s = store.getState()
expect(s.activeWorktreeId).toBeNull()
expect(s.activeTabId).toBeNull()
expect(s.tabsByWorktree[wt]).toEqual([])
expect(s.unifiedTabsByWorktree[wt]).toEqual([])
})
it('keeps terminal numbering stable when a live agent renames an existing tab', () => {
const store = createTestStore()
const wt = 'repo1::/path/wt1'
+38 -1
View File
@@ -538,6 +538,12 @@ export const createTabsSlice: StateCreator<AppState, [], [], TabsSlice> = (set,
nextLayoutByWorktree = collapsedState.layoutByWorktree
nextActiveGroupIdByWorktree = collapsedState.activeGroupIdByWorktree
}
const shouldDeactivateWorktree =
current.activeWorktreeId === worktreeId &&
nextTabs.length === 0 &&
(current.tabsByWorktree[worktreeId] ?? []).length === 0 &&
(current.browserTabsByWorktree[worktreeId] ?? []).length === 0 &&
!current.openFiles.some((file) => file.worktreeId === worktreeId)
return {
unifiedTabsByWorktree: { ...current.unifiedTabsByWorktree, [worktreeId]: nextTabs },
groupsByWorktree: {
@@ -546,7 +552,38 @@ export const createTabsSlice: StateCreator<AppState, [], [], TabsSlice> = (set,
},
layoutByWorktree: nextLayoutByWorktree,
activeGroupIdByWorktree: nextActiveGroupIdByWorktree,
...(current.activeWorktreeId === worktreeId
// Why: the split-group model can legally derive "terminal with no
// active tab" after the final unified tab closes. That leaves the
// worktree selected but render-empty, so the workspace shows a blank
// pane instead of Orca's landing screen. When that happens, write the
// landing-state fallback directly instead of recomputing active-surface
// fields from a worktree that is no longer active.
...(shouldDeactivateWorktree
? {
activeWorktreeId: null,
activeTabId: null,
activeBrowserTabId: null,
activeFileId: null,
activeTabType: 'terminal' as const,
activeTabIdByWorktree: {
...current.activeTabIdByWorktree,
[worktreeId]: null
},
activeBrowserTabIdByWorktree: {
...current.activeBrowserTabIdByWorktree,
[worktreeId]: null
},
activeFileIdByWorktree: {
...current.activeFileIdByWorktree,
[worktreeId]: null
},
activeTabTypeByWorktree: {
...current.activeTabTypeByWorktree,
[worktreeId]: 'terminal'
}
}
: {}),
...(!shouldDeactivateWorktree && current.activeWorktreeId === worktreeId
? buildActiveSurfacePatch(
{
...current,