mirror of
https://github.com/jlengrand/Maestro.git
synced 2026-03-10 08:31:19 +00:00
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.
This commit is contained in:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user