diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx
index e51cf2ae6..9e7baa240 100644
--- a/src/renderer/src/App.tsx
+++ b/src/renderer/src/App.tsx
@@ -99,6 +99,7 @@ function App(): React.JSX.Element {
const refreshAllGitHub = useAppStore((s) => s.refreshAllGitHub)
const hydrateWorkspaceSession = useAppStore((s) => s.hydrateWorkspaceSession)
const hydrateEditorSession = useAppStore((s) => s.hydrateEditorSession)
+ const hydrateTabsSession = useAppStore((s) => s.hydrateTabsSession)
const reconnectPersistedTerminals = useAppStore((s) => s.reconnectPersistedTerminals)
const hydratePersistedUI = useAppStore((s) => s.hydratePersistedUI)
const openModal = useAppStore((s) => s.openModal)
@@ -117,6 +118,10 @@ function App(): React.JSX.Element {
const activeTabTypeByWorktree = useAppStore((s) => s.activeTabTypeByWorktree)
const activeTabIdByWorktree = useAppStore((s) => s.activeTabIdByWorktree)
+ // Unified tab state for session persistence and titlebar hiding
+ const unifiedTabsByWorktree = useAppStore((s) => s.unifiedTabsByWorktree)
+ const groupsByWorktree = useAppStore((s) => s.groupsByWorktree)
+ const layoutByWorktree = useAppStore((s) => s.layoutByWorktree)
// Right sidebar + editor state
const toggleRightSidebar = useAppStore((s) => s.toggleRightSidebar)
const rightSidebarOpen = useAppStore((s) => s.rightSidebarOpen)
@@ -155,6 +160,7 @@ function App(): React.JSX.Element {
hydratePersistedUI(persistedUI)
hydrateWorkspaceSession(session)
hydrateEditorSession(session)
+ hydrateTabsSession(session)
await reconnectPersistedTerminals(abortController.signal)
syncZoomCSSVar()
}
@@ -205,6 +211,7 @@ function App(): React.JSX.Element {
hydratePersistedUI,
hydrateWorkspaceSession,
hydrateEditorSession,
+ hydrateTabsSession,
reconnectPersistedTerminals
])
@@ -243,7 +250,10 @@ function App(): React.JSX.Element {
terminalLayoutsByTabId,
activeWorktreeIdsOnShutdown,
activeTabIdByWorktree,
- ...buildEditorSessionData(openFiles, activeFileIdByWorktree, activeTabTypeByWorktree)
+ ...buildEditorSessionData(openFiles, activeFileIdByWorktree, activeTabTypeByWorktree),
+ unifiedTabs: unifiedTabsByWorktree,
+ tabGroups: groupsByWorktree,
+ tabGroupLayouts: layoutByWorktree
})
}, 150)
@@ -258,7 +268,10 @@ function App(): React.JSX.Element {
openFiles,
activeFileIdByWorktree,
activeTabTypeByWorktree,
- activeTabIdByWorktree
+ activeTabIdByWorktree,
+ unifiedTabsByWorktree,
+ groupsByWorktree,
+ layoutByWorktree
])
// On shutdown, capture terminal scrollback buffers and flush to disk.
@@ -291,7 +304,10 @@ function App(): React.JSX.Element {
state.openFiles,
state.activeFileIdByWorktree,
state.activeTabTypeByWorktree
- )
+ ),
+ unifiedTabs: state.unifiedTabsByWorktree,
+ tabGroups: state.groupsByWorktree,
+ tabGroupLayouts: state.layoutByWorktree
})
}
window.addEventListener('beforeunload', captureAndFlush)
@@ -532,7 +548,10 @@ function App(): React.JSX.Element {
{/* Why: portal target for the TabBar rendered by Terminal.tsx.
Hidden when tabs should not be visible (settings view, no active worktree)
- so the portal content does not leak through. */}
+ so the portal content does not leak through. When splits are active,
+ Terminal.tsx skips the portal so the div stays empty, but it must
+ remain visible as a flex-1 spacer to keep the right sidebar toggle
+ pushed to the far right. */}
import('./editor/EditorPanel'))
-
export default function Terminal(): React.JSX.Element | null {
const activeWorktreeId = useAppStore((s) => s.activeWorktreeId)
- const activeView = useAppStore((s) => s.activeView)
+
const worktreesByRepo = useAppStore((s) => s.worktreesByRepo)
const tabsByWorktree = useAppStore((s) => s.tabsByWorktree)
const activeTabId = useAppStore((s) => s.activeTabId)
@@ -53,6 +52,18 @@ export default function Terminal(): React.JSX.Element | null {
const tabBarOrderByWorktree = useAppStore((s) => s.tabBarOrderByWorktree)
const tabBarOrder = activeWorktreeId ? tabBarOrderByWorktree[activeWorktreeId] : undefined
+ // Tab group split state
+ const layout = useAppStore((s) =>
+ activeWorktreeId ? s.layoutByWorktree[activeWorktreeId] : undefined
+ )
+ const hasSplitGroups = layout?.type === 'split'
+ const focusedGroupId = useAppStore((s) =>
+ activeWorktreeId ? s.activeGroupIdByWorktree[activeWorktreeId] : undefined
+ )
+ const splitTabToGroup = useAppStore((s) => s.splitTabToGroup)
+ const createUnifiedTab = useAppStore((s) => s.createUnifiedTab)
+ const closeUnifiedTab = useAppStore((s) => s.closeUnifiedTab)
+
const tabs = activeWorktreeId ? (tabsByWorktree[activeWorktreeId] ?? []) : []
const allWorktrees = Object.values(worktreesByRepo).flat()
@@ -85,8 +96,9 @@ export default function Terminal(): React.JSX.Element | null {
return
}
closeFile(fileId)
+ closeUnifiedTab(fileId)
},
- [closeFile]
+ [closeFile, closeUnifiedTab]
)
const handleSaveDialogSave = useCallback(async () => {
@@ -117,8 +129,9 @@ export default function Terminal(): React.JSX.Element | null {
await requestEditorSaveQuiesce({ fileId: saveDialogFileId })
markFileDirty(saveDialogFileId, false)
closeFile(saveDialogFileId)
+ closeUnifiedTab(saveDialogFileId)
setSaveDialogFileId(null)
- }, [saveDialogFileId, closeFile, markFileDirty])
+ }, [saveDialogFileId, closeFile, closeUnifiedTab, markFileDirty])
const handleSaveDialogCancel = useCallback(() => {
setSaveDialogFileId(null)
@@ -177,14 +190,25 @@ export default function Terminal(): React.JSX.Element | null {
return
}
initialTabCreationGuardRef.current = activeWorktreeId
- createTab(activeWorktreeId)
- }, [workspaceSessionReady, activeWorktreeId, tabs.length, worktreeFiles.length, createTab])
+ const newTab = createTab(activeWorktreeId)
+ // Why: keep TabsSlice in sync so tab group splits can find this tab.
+ createUnifiedTab(activeWorktreeId, 'terminal', { id: newTab.id, label: newTab.title })
+ }, [
+ workspaceSessionReady,
+ activeWorktreeId,
+ tabs.length,
+ worktreeFiles.length,
+ createTab,
+ createUnifiedTab
+ ])
const handleNewTab = useCallback(() => {
if (!activeWorktreeId) {
return
}
const newTab = createTab(activeWorktreeId)
+ // Why: keep TabsSlice in sync so tab group splits can find this tab.
+ createUnifiedTab(activeWorktreeId, 'terminal', { id: newTab.id, label: newTab.title })
setActiveTabType('terminal')
// Why: persist the tab bar order with the new terminal at the end of the
// current visual order. Without this, reconcileOrder falls back to
@@ -209,7 +233,7 @@ export default function Terminal(): React.JSX.Element | null {
const order = base.filter((id) => id !== newTab.id)
order.push(newTab.id)
setTabBarOrder(activeWorktreeId, order)
- }, [activeWorktreeId, createTab, setActiveTabType, setTabBarOrder])
+ }, [activeWorktreeId, createTab, createUnifiedTab, setActiveTabType, setTabBarOrder])
const handleCloseTab = useCallback(
(tabId: string) => {
@@ -226,6 +250,7 @@ export default function Terminal(): React.JSX.Element | null {
const currentTabs = state.tabsByWorktree[owningWorktreeId] ?? []
if (currentTabs.length <= 1) {
closeTab(tabId)
+ closeUnifiedTab(tabId)
if (state.activeWorktreeId === owningWorktreeId) {
// Why: only deactivate the worktree when no tabs of any kind remain.
// Editor files are a separate tab type; closing the last terminal tab
@@ -250,8 +275,9 @@ export default function Terminal(): React.JSX.Element | null {
}
}
closeTab(tabId)
+ closeUnifiedTab(tabId)
},
- [closeTab, setActiveTab, setActiveFile, setActiveTabType, setActiveWorktree]
+ [closeTab, closeUnifiedTab, setActiveTab, setActiveFile, setActiveTabType, setActiveWorktree]
)
const handlePtyExit = useCallback(
@@ -274,10 +300,11 @@ export default function Terminal(): React.JSX.Element | null {
for (const tab of currentTabs) {
if (tab.id !== tabId) {
closeTab(tab.id)
+ closeUnifiedTab(tab.id)
}
}
},
- [activeWorktreeId, closeTab, setActiveTab]
+ [activeWorktreeId, closeTab, closeUnifiedTab, setActiveTab]
)
const handleCloseTabsToRight = useCallback(
@@ -293,9 +320,10 @@ export default function Terminal(): React.JSX.Element | null {
const rightTabs = currentTabs.slice(index + 1)
for (const tab of rightTabs) {
closeTab(tab.id)
+ closeUnifiedTab(tab.id)
}
},
- [activeWorktreeId, closeTab]
+ [activeWorktreeId, closeTab, closeUnifiedTab]
)
const handleActivateTab = useCallback(
@@ -320,6 +348,31 @@ export default function Terminal(): React.JSX.Element | null {
[setActiveTab]
)
+ const handleSplitTab = useCallback(
+ (tabId: string, direction: 'left' | 'right' | 'up' | 'down') => {
+ splitTabToGroup(tabId, direction)
+ // Why: after splitting, the new group's terminal tab needs a PTY.
+ // The new tab was created in TabsSlice but TerminalSlice also needs
+ // a matching entry for PTY lifecycle. We create it in TerminalSlice
+ // so TerminalPane can mount and spawn a PTY.
+ if (activeWorktreeId) {
+ const state = useAppStore.getState()
+ const newGroupId = state.activeGroupIdByWorktree[activeWorktreeId]
+ const newGroupTabs = (state.unifiedTabsByWorktree[activeWorktreeId] ?? []).filter(
+ (t) => t.groupId === newGroupId && t.contentType === 'terminal'
+ )
+ // The newest terminal tab in the new group needs a TerminalSlice entry
+ for (const ut of newGroupTabs) {
+ const exists = (state.tabsByWorktree[activeWorktreeId] ?? []).some((t) => t.id === ut.id)
+ if (!exists) {
+ createTab(activeWorktreeId, ut.id)
+ }
+ }
+ }
+ },
+ [splitTabToGroup, activeWorktreeId, createTab]
+ )
+
// Keyboard shortcuts
useEffect(() => {
if (!activeWorktreeId) {
@@ -353,16 +406,36 @@ export default function Terminal(): React.JSX.Element | null {
// Cmd/Ctrl+Shift+] and Cmd/Ctrl+Shift+[ - switch tabs
if (mod && e.shiftKey && (e.key === ']' || e.key === '[') && !e.repeat) {
const state = useAppStore.getState()
- const currentTerminalTabs = state.tabsByWorktree[activeWorktreeId] ?? []
- const currentEditorFiles = activeWorktreeId
- ? state.openFiles.filter((f) => f.worktreeId === activeWorktreeId)
- : []
- // Build unified tab list: terminal tabs then editor tabs
- const allTabIds: { type: 'terminal' | 'editor'; id: string }[] = [
- ...currentTerminalTabs.map((t) => ({ type: 'terminal' as const, id: t.id })),
- ...currentEditorFiles.map((f) => ({ type: 'editor' as const, id: f.id }))
- ]
+ // Why: when splits are active, tab cycling must stay within the
+ // focused group so the user doesn't jump between panels unexpectedly.
+ const currentGroupId = state.activeGroupIdByWorktree[activeWorktreeId]
+ const hasLayout = state.layoutByWorktree[activeWorktreeId]?.type === 'split'
+ const groupFilter =
+ hasLayout && currentGroupId
+ ? (t: { groupId?: string }) => t.groupId === currentGroupId
+ : () => true
+
+ const unifiedTabs = (state.unifiedTabsByWorktree[activeWorktreeId] ?? []).filter(
+ groupFilter
+ )
+
+ const allTabIds: { type: 'terminal' | 'editor'; id: string }[] = unifiedTabs.map((t) => ({
+ type: t.contentType === 'terminal' ? ('terminal' as const) : ('editor' as const),
+ id: t.id
+ }))
+
+ // Fallback for single-group mode without unified tabs populated
+ if (allTabIds.length === 0) {
+ const currentTerminalTabs = state.tabsByWorktree[activeWorktreeId] ?? []
+ const currentEditorFiles = activeWorktreeId
+ ? state.openFiles.filter((f) => f.worktreeId === activeWorktreeId)
+ : []
+ allTabIds.push(
+ ...currentTerminalTabs.map((t) => ({ type: 'terminal' as const, id: t.id })),
+ ...currentEditorFiles.map((f) => ({ type: 'editor' as const, id: f.id }))
+ )
+ }
if (allTabIds.length > 1) {
e.preventDefault()
@@ -435,10 +508,11 @@ export default function Terminal(): React.JSX.Element | null {
>
- {/* Why: the tab bar is rendered into the titlebar via a portal so it
- shares the same visual row as the "Orca" title. The portal target
- (#titlebar-tabs) lives in App.tsx's titlebar. */}
- {activeWorktreeId &&
+ {/* Why: when tab groups are split, each group renders its own inline
+ tab bar inside TabGroupPanel. The titlebar portal is skipped so it
+ doesn't show a duplicate set of tabs. */}
+ {!hasSplitGroups &&
+ activeWorktreeId &&
titlebarTabsTarget &&
createPortal(
,
titlebarTabsTarget
)}
- {/* Terminal panes container - hidden when editor tab active */}
-
0 ? 'hidden' : ''}`}
- >
+ {/* Why: always render through TabGroupSplitLayout — even for a single
+ group — so that splitting never unmounts the original TabGroupPanel.
+ The CSS Grid flat rendering in TabGroupSplitLayout keeps all
+ TabGroupPanels as stable keyed siblings, preserving xterm instances
+ and PTY connections across layout changes. */}
+ {activeWorktreeId && layout && (
+
+ )}
+
+ {/* Why: non-active worktrees keep their TerminalPanes mounted (hidden)
+ so PTY connections survive worktree switches. The active worktree's
+ terminals are rendered by TabGroupPanel inside TabGroupSplitLayout. */}
+
{allWorktrees
- .filter((wt) => mountedWorktreeIdsRef.current.has(wt.id))
+ .filter((wt) => mountedWorktreeIdsRef.current.has(wt.id) && wt.id !== activeWorktreeId)
.map((worktree) => {
const worktreeTabs = tabsByWorktree[worktree.id] ?? []
- const isVisible = activeView !== 'settings' && worktree.id === activeWorktreeId
-
- return (
-
- {worktreeTabs.map((tab) => (
- handlePtyExit(tab.id, ptyId)}
- onCloseTab={() => handleCloseTab(tab.id)}
- />
- ))}
-
- )
+ return worktreeTabs.map((tab) => (
+
handlePtyExit(tab.id, ptyId)}
+ onCloseTab={() => handleCloseTab(tab.id)}
+ />
+ ))
})}
- {/* Why: v1.0.85 only mounted the visible editor surface, which kept
- hidden editor effects out of app shutdown. Autosave now lives in the
- narrow EditorAutosaveController above, so the full EditorPanel can go
- back to the safer "mount only while visible" lifecycle. */}
- {activeWorktreeId && activeTabType === 'editor' && worktreeFiles.length > 0 && (
-
- Loading editor...
-
- }
- >
-
-
- )}
-
{/* Save confirmation dialog */}