From 1048021e85b4e2ca3d7545cf916d24fb655d1806 Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Mon, 23 Mar 2026 09:52:26 -0700 Subject: [PATCH] fix: preserve terminal state when clearing active worktree (#51) --- src/renderer/src/App.tsx | 20 ++++--- src/renderer/src/components/Terminal.tsx | 67 +++++++++++++----------- 2 files changed, 45 insertions(+), 42 deletions(-) diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 12be1363908..d1e50bb7ead 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -285,17 +285,15 @@ function App(): React.JSX.Element {
{showSidebar ? : null}
- {activeWorktreeId && ( -
- -
- )} +
+ +
{activeView === 'settings' ? : !activeWorktreeId ? : null}
{showSidebar && rightSidebarOpen ? : null} diff --git a/src/renderer/src/components/Terminal.tsx b/src/renderer/src/components/Terminal.tsx index 697ae54a393..18f4f32318c 100644 --- a/src/renderer/src/components/Terminal.tsx +++ b/src/renderer/src/components/Terminal.tsx @@ -105,6 +105,13 @@ export default function Terminal(): React.JSX.Element | null { if (activeWorktreeId) { mountedWorktreeIdsRef.current.add(activeWorktreeId) } + // Prune IDs of worktrees that no longer exist (deleted/removed) + const allWorktreeIds = new Set(allWorktrees.map((wt) => wt.id)) + for (const id of mountedWorktreeIdsRef.current) { + if (!allWorktreeIds.has(id)) { + mountedWorktreeIdsRef.current.delete(id) + } + } const tabBarRef = useRef(null) const initialTabCreationGuardRef = useRef(null) @@ -306,43 +313,41 @@ export default function Terminal(): React.JSX.Element | null { return () => window.removeEventListener('beforeunload', handler) }, []) - if (!activeWorktreeId) { - return null - } - return ( -
+
{/* Animated tab bar container using CSS grid for smooth height animation */}
= 2 ? '1fr' : '0fr' }} + style={{ gridTemplateRows: activeWorktreeId && totalTabs >= 2 ? '1fr' : '0fr' }} >
- { - setActiveFile(fileId) - setActiveTabType('editor') - }} - onCloseFile={handleCloseFile} - onCloseAllFiles={closeAllFiles} - /> + {activeWorktreeId && ( + { + setActiveFile(fileId) + setActiveTabType('editor') + }} + onCloseFile={handleCloseFile} + onCloseAllFiles={closeAllFiles} + /> + )}
@@ -378,7 +383,7 @@ export default function Terminal(): React.JSX.Element | null {
{/* Editor panel - shown when editor tab is active */} - {activeTabType === 'editor' && openFiles.length > 0 && ( + {activeWorktreeId && activeTabType === 'editor' && openFiles.length > 0 && (