MAESTRO: Clear activeFileTabId when selecting an AI tab

Modify setActiveTab function to deselect any active file preview tab
when an AI tab is selected. This ensures only one tab type (AI or file)
is active at a time. Updated early-return condition to also check if
activeFileTabId is null before returning unchanged session.
This commit is contained in:
Pedram Amini
2026-02-02 03:25:59 -06:00
parent 850cfdd109
commit 115d9a042b
2 changed files with 24 additions and 2 deletions

View File

@@ -72,6 +72,9 @@ function createMockSession(overrides: Partial<Session> = {}): Session {
aiTabs: [],
activeTabId: '',
closedTabHistory: [],
filePreviewTabs: [],
activeFileTabId: null,
unifiedTabOrder: [],
...overrides,
};
}
@@ -578,6 +581,22 @@ describe('tabHelpers', () => {
expect(result!.session.activeTabId).toBe('tab-2');
expect(result!.tab).toBe(tab2);
});
it('clears activeFileTabId when selecting an AI tab', () => {
const tab = createMockTab({ id: 'tab-1' });
const session = createMockSession({
aiTabs: [tab],
activeTabId: 'tab-1',
activeFileTabId: 'file-tab-1', // A file tab was active
});
const result = setActiveTab(session, 'tab-1');
// Should return a new session with activeFileTabId cleared
expect(result!.session).not.toBe(session);
expect(result!.session.activeFileTabId).toBeNull();
expect(result!.session.activeTabId).toBe('tab-1');
});
});
describe('getWriteModeTab', () => {

View File

@@ -440,19 +440,22 @@ export function setActiveTab(session: Session, tabId: string): SetActiveTabResul
return null;
}
// If already active, return current state (no mutation needed)
if (session.activeTabId === tabId) {
// If already active and no file tab is selected, return current state (no mutation needed)
if (session.activeTabId === tabId && session.activeFileTabId === null) {
return {
tab: targetTab,
session,
};
}
// When selecting an AI tab, deselect any active file preview tab
// This ensures only one tab type (AI or file) is active at a time
return {
tab: targetTab,
session: {
...session,
activeTabId: tabId,
activeFileTabId: null,
},
};
}