From fc3872ea73f5645f459c231d897de147e2f3dda5 Mon Sep 17 00:00:00 2001 From: Pedram Amini Date: Mon, 2 Feb 2026 19:19:21 -0600 Subject: [PATCH] fix(tabs): restore file preview tabs with Cmd+Shift+T handleCloseCurrentTab was duplicating file tab close logic inline but not adding closed tabs to unifiedClosedTabHistory, causing Cmd+Shift+T to restore a different tab instead of the most recently closed one. Now uses closeFileTabHelper which properly tracks history. --- src/renderer/App.tsx | 61 +++----------------------------------------- 1 file changed, 4 insertions(+), 57 deletions(-) diff --git a/src/renderer/App.tsx b/src/renderer/App.tsx index 49936c76..603efea3 100644 --- a/src/renderer/App.tsx +++ b/src/renderer/App.tsx @@ -5773,66 +5773,13 @@ You are taking over this conversation. Based on the context above, provide a bri if (session.activeFileTabId) { const tabId = session.activeFileTabId; // File tabs can always be closed (no wizard confirmation needed) + // Use the closeFileTabHelper to properly add to unifiedClosedTabHistory for Cmd+Shift+T setSessions((prev) => prev.map((s) => { if (s.id !== activeSessionIdRef.current) return s; - - // Find the tab to close - const tabToClose = s.filePreviewTabs.find((tab) => tab.id === tabId); - if (!tabToClose) return s; - - // Remove from filePreviewTabs - const updatedFilePreviewTabs = s.filePreviewTabs.filter( - (tab) => tab.id !== tabId - ); - - // Remove from unifiedTabOrder - const closedTabIndex = s.unifiedTabOrder.findIndex( - (ref) => ref.type === 'file' && ref.id === tabId - ); - const updatedUnifiedTabOrder = s.unifiedTabOrder.filter( - (ref) => !(ref.type === 'file' && ref.id === tabId) - ); - - // Determine new active tab if we closed the active file tab - let newActiveFileTabId: string | null = null; - let newActiveTabId = s.activeTabId; - - // This was the active tab - find the next tab in unifiedTabOrder - if (updatedUnifiedTabOrder.length > 0 && closedTabIndex !== -1) { - // Try to select the tab at the same position (or previous if at end) - const newIndex = Math.min( - closedTabIndex, - updatedUnifiedTabOrder.length - 1 - ); - const nextTabRef = updatedUnifiedTabOrder[newIndex]; - - if (nextTabRef.type === 'file') { - // Next tab is a file tab - newActiveFileTabId = nextTabRef.id; - } else { - // Next tab is an AI tab - switch to it - newActiveTabId = nextTabRef.id; - newActiveFileTabId = null; - } - } else if (updatedUnifiedTabOrder.length > 0) { - // Fallback: just select the first available tab - const firstTabRef = updatedUnifiedTabOrder[0]; - if (firstTabRef.type === 'file') { - newActiveFileTabId = firstTabRef.id; - } else { - newActiveTabId = firstTabRef.id; - newActiveFileTabId = null; - } - } - - return { - ...s, - filePreviewTabs: updatedFilePreviewTabs, - unifiedTabOrder: updatedUnifiedTabOrder, - activeFileTabId: newActiveFileTabId, - activeTabId: newActiveTabId, - }; + const result = closeFileTabHelper(s, tabId); + if (!result) return s; + return result.session; }) ); return { type: 'file', tabId };