Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions apps/web/src/rightPanelStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
});
Expand All @@ -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: [],
});
Expand Down Expand Up @@ -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: [],
});
Expand Down
14 changes: 11 additions & 3 deletions apps/web/src/rightPanelStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ export const useRightPanelStore = create<RightPanelStoreState>()(
const fallback = surfaces[Math.min(index, surfaces.length - 1)] ?? null;
return {
...current,
isOpen: surfaces.length > 0 && current.isOpen,
surfaces,
activeSurfaceId:
current.activeSurfaceId === surfaceId
Expand Down Expand Up @@ -378,9 +379,16 @@ export const useRightPanelStore = create<RightPanelStoreState>()(
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) =>
Expand Down Expand Up @@ -417,7 +425,7 @@ export const useRightPanelStore = create<RightPanelStoreState>()(
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) =>
Expand Down
Loading