From 7295f6394a45b974db69e59be7c6ea363e4569ad Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 19 Jun 2026 23:46:04 -0700 Subject: [PATCH] Close right panel when its last tab closes --- apps/web/src/rightPanelStore.test.ts | 12 ++++++------ apps/web/src/rightPanelStore.ts | 14 +++++++++++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/apps/web/src/rightPanelStore.test.ts b/apps/web/src/rightPanelStore.test.ts index fb6d56f98c7..b48f6e7ebb5 100644 --- a/apps/web/src/rightPanelStore.test.ts +++ b/apps/web/src/rightPanelStore.test.ts @@ -338,12 +338,12 @@ describe("rightPanelStore", () => { }); }); - it("closing the final terminal pane removes its surface but keeps the panel open", () => { + it("closing the final terminal pane removes its surface and closes the panel", () => { useRightPanelStore.getState().openTerminal(refA, "term-1"); useRightPanelStore.getState().closeTerminal(refA, "terminal:term-1", "term-1"); expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({ - isOpen: true, + isOpen: false, activeSurfaceId: null, surfaces: [], }); @@ -359,12 +359,12 @@ describe("rightPanelStore", () => { ); }); - it("closing the final surface leaves the panel open and empty", () => { + it("closing the final surface closes the panel", () => { useRightPanelStore.getState().openTerminal(refA, "term-1"); useRightPanelStore.getState().closeSurface(refA, "terminal:term-1"); expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({ - isOpen: true, + isOpen: false, activeSurfaceId: null, surfaces: [], }); @@ -406,14 +406,14 @@ describe("rightPanelStore", () => { }); }); - it("closing all surfaces leaves the panel open and empty", () => { + it("closing all surfaces closes the panel", () => { useRightPanelStore.getState().openBrowser(refA, "tab-a"); useRightPanelStore.getState().openFile(refA, "src/index.ts"); useRightPanelStore.getState().closeAllSurfaces(refA); expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({ - isOpen: true, + isOpen: false, activeSurfaceId: null, surfaces: [], }); diff --git a/apps/web/src/rightPanelStore.ts b/apps/web/src/rightPanelStore.ts index 26dfe8c5153..70d163306cc 100644 --- a/apps/web/src/rightPanelStore.ts +++ b/apps/web/src/rightPanelStore.ts @@ -340,6 +340,7 @@ export const useRightPanelStore = create()( const fallback = surfaces[Math.min(index, surfaces.length - 1)] ?? null; return { ...current, + isOpen: surfaces.length > 0 && current.isOpen, surfaces, activeSurfaceId: current.activeSurfaceId === surfaceId @@ -378,9 +379,16 @@ export const useRightPanelStore = create()( const index = current.surfaces.findIndex((surface) => surface.id === surfaceId); if (index < 0) return current; const surfaces = current.surfaces.filter((surface) => surface.id !== surfaceId); - if (current.activeSurfaceId !== surfaceId) return { ...current, surfaces }; + if (current.activeSurfaceId !== surfaceId) { + return { ...current, isOpen: surfaces.length > 0 && current.isOpen, surfaces }; + } const fallback = surfaces[Math.min(index, surfaces.length - 1)] ?? null; - return { ...current, surfaces, activeSurfaceId: fallback?.id ?? null }; + return { + ...current, + isOpen: surfaces.length > 0 && current.isOpen, + surfaces, + activeSurfaceId: fallback?.id ?? null, + }; }), })), closeOtherSurfaces: (ref, surfaceId) => @@ -417,7 +425,7 @@ export const useRightPanelStore = create()( byThreadKey: updateThread(state.byThreadKey, scopedThreadKey(ref), (current) => current.surfaces.length === 0 ? current - : { ...current, isOpen: true, surfaces: [], activeSurfaceId: null }, + : { ...current, isOpen: false, surfaces: [], activeSurfaceId: null }, ), })), reconcileBrowserSurfaces: (ref, tabIds) =>