Skip to content

Commit 0e7230f

Browse files
Copilotrajbos
andcommitted
Add tab state persistence to diagnostics view
Co-authored-by: rajbos <6085745+rajbos@users.noreply.github.com>
1 parent b50d066 commit 0e7230f

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

src/webview/diagnostics/main.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ type DiagnosticsData = {
3939
cacheInfo?: CacheInfo;
4040
};
4141

42-
declare function acquireVsCodeApi<TState = unknown>(): {
42+
type DiagnosticsViewState = {
43+
activeTab?: string;
44+
};
45+
46+
declare function acquireVsCodeApi<TState = DiagnosticsViewState>(): {
4347
postMessage: (message: unknown) => void;
4448
setState: (newState: TState) => void;
4549
getState: () => TState | undefined;
@@ -49,7 +53,7 @@ declare global {
4953
interface Window { __INITIAL_DIAGNOSTICS__?: DiagnosticsData; }
5054
}
5155

52-
const vscode = acquireVsCodeApi();
56+
const vscode = acquireVsCodeApi<DiagnosticsViewState>();
5357
const initialData = window.__INITIAL_DIAGNOSTICS__;
5458

5559
// Sorting and filtering state
@@ -783,6 +787,11 @@ function renderLayout(data: DiagnosticsData): void {
783787
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
784788
const content = document.getElementById(`tab-${tabId}`);
785789
if (content) { content.classList.add('active'); }
790+
791+
// Save the active tab state
792+
if (tabId) {
793+
vscode.setState({ activeTab: tabId });
794+
}
786795
});
787796
});
788797

@@ -934,6 +943,23 @@ function renderLayout(data: DiagnosticsData): void {
934943
setupSortHandlers();
935944
setupEditorFilterHandlers();
936945
setupFileLinks();
946+
947+
// Restore active tab from saved state
948+
const savedState = vscode.getState();
949+
if (savedState?.activeTab) {
950+
const tabToActivate = document.querySelector(`.tab[data-tab="${savedState.activeTab}"]`);
951+
const contentToActivate = document.getElementById(`tab-${savedState.activeTab}`);
952+
953+
if (tabToActivate && contentToActivate) {
954+
// Remove active class from all tabs and contents
955+
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
956+
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
957+
958+
// Activate the saved tab
959+
tabToActivate.classList.add('active');
960+
contentToActivate.classList.add('active');
961+
}
962+
}
937963
}
938964

939965
async function bootstrap(): Promise<void> {

0 commit comments

Comments
 (0)