GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(web): restore folder breadcrumb trails when reopening tabs (#30706) · Pipyakas/t3code@10f88f3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/web/src
    • reopenClosedView.test.ts
    • reopenClosedView.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/web/src/reopenClosedView.test.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/reopenClosedView.test.ts
+120-22Lines changed: 120 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { __setClientSettingsForTests } from "./hooks/useSettings";
1212
import { readThreadPreviewState, resetPreviewStateForTests } from "./previewStateStore";
1313
import { planNextReopen, type ReopenOwnerState, reopenClosedView } from "./reopenClosedView";
1414
import {
15+
hostRightPanel,
1516
selectThreadRightPanelState,
1617
type ThreadRightPanelState,
1718
useRightPanelStore,
@@ -40,43 +41,140 @@ beforeEach(() => {
4041
});
4142

4243
describe("reopenClosedView", () => {
43-
it("restores a file tab at its line without creating a browser session", async () => {
44-
const openPreview = vi.fn();
45-
const reopened = await reopenClosedView(
46-
{
47-
kind: "panel-tab",
44+
it.each([
45+
{ relativePath: "src/app.ts", line: 18, folderTrail: undefined },
46+
{ relativePath: "apps", line: null, folderTrail: "apps/web/src" },
47+
{ relativePath: "", line: null, folderTrail: "apps/web/src" },
48+
])(
49+
"restores the captured file or folder tab at '$relativePath'",
50+
async ({ relativePath, line, folderTrail }) => {
51+
const panels = useRightPanelStore.getState();
52+
if (folderTrail === undefined) panels.openFile(threadRef, relativePath, line ?? undefined);
53+
else {
54+
panels.openFile(threadRef, folderTrail);
55+
panels.navigateFolder(threadRef, `file:${folderTrail}`, relativePath, folderTrail);
56+
}
57+
const expected =
58+
relativePath === ""
59+
? { kind: "files", id: "files", folderTrail }
60+
: {
61+
kind: "file",
62+
id: `file:${relativePath}`,
63+
relativePath,
64+
revealLine: line,
65+
revealRequestId: 1,
66+
...(folderTrail === undefined ? {} : { folderTrail }),
67+
};
68+
const before = selectThreadRightPanelState(
69+
useRightPanelStore.getState().byThreadKey,
4870
threadRef,
49-
surface: {
50-
kind: "file",
51-
id: "file:src/app.ts",
52-
relativePath: "src/app.ts",
53-
revealLine: 18,
54-
revealRequestId: 1,
55-
},
56-
},
57-
{ openPreview, workspaceAvailable: true },
58-
);
59-
expect(reopened).toBe(true);
60-
const state = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, threadRef);
61-
expect(state.isOpen).toBe(true);
62-
expect(state.surfaces).toMatchObject([{ id: "file:src/app.ts", revealLine: 18 }]);
63-
expect(openPreview).not.toHaveBeenCalled();
64-
});
71+
);
72+
expect(before.surfaces).toEqual([expected]);
73+
panels.closeSurface(threadRef, expected.id);
74+
expect(
75+
selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, threadRef).surfaces,
76+
).toEqual([]);
77+
const entries = useClosedViewStore.getState().entries;
78+
expect(entries).toEqual([
79+
{ id: expect.any(String), kind: "panel-tab", threadRef, surface: expected },
80+
]);
81+
const openPreview = vi.fn();
82+
const reopened = await reopenClosedView(entries[0]!, {
83+
openPreview,
84+
workspaceAvailable: true,
85+
});
86+
expect(reopened).toBe(true);
87+
const state = selectThreadRightPanelState(
88+
useRightPanelStore.getState().byThreadKey,
89+
threadRef,
90+
);
91+
expect(state.isOpen).toBe(true);
92+
expect(state.activeSurfaceId).toBe(expected.id);
93+
expect(state.surfaces).toEqual([expected]);
94+
expect(openPreview).not.toHaveBeenCalled();
95+
},
96+
);
97+
98+
it.each([
99+
{ hosted: false, folderTrail: "packages/contracts/src" },
100+
{ hosted: false, folderTrail: undefined },
101+
{ hosted: true, folderTrail: "packages/contracts/src" },
102+
{ hosted: true, folderTrail: undefined },
103+
])(
104+
"preserves a hidden root tab with trail $folderTrail (hosted: $hosted)",
105+
async ({ hosted, folderTrail }) => {
106+
const panels = useRightPanelStore.getState();
107+
panels.openFile(threadRef, "apps/web/src");
108+
panels.navigateFolder(threadRef, "file:apps/web/src", "", "apps/web/src");
109+
panels.closeSurface(threadRef, "files");
110+
const entry = useClosedViewStore.getState().entries[0]!;
111+
const hostRef = hosted
112+
? { ...threadRef, threadId: "host" as ScopedThreadRef["threadId"] }
113+
: threadRef;
114+
const unhost = hosted ? hostRightPanel(threadRef, hostRef) : undefined;
115+
try {
116+
if (folderTrail === undefined) panels.open(threadRef, "files");
117+
else {
118+
panels.openFile(threadRef, folderTrail);
119+
panels.navigateFolder(threadRef, `file:${folderTrail}`, "", folderTrail);
120+
}
121+
panels.close(threadRef);
122+
const before = selectThreadRightPanelState(
123+
useRightPanelStore.getState().byThreadKey,
124+
hostRef,
125+
);
126+
expect(before.isOpen).toBe(false);
127+
const plan = planNextReopen([entry], () => ({
128+
environmentKnown: true,
129+
catalogReady: true,
130+
ownerExists: true,
131+
sideChatExists: true,
132+
shellLive: true,
133+
panel: before,
134+
}));
135+
expect(plan.restore).toBe(entry);
136+
const openPreview = vi.fn();
137+
expect(
138+
await reopenClosedView(plan.restore!, { openPreview, workspaceAvailable: true }),
139+
).toBe(true);
140+
const after = selectThreadRightPanelState(
141+
useRightPanelStore.getState().byThreadKey,
142+
hostRef,
143+
);
144+
expect(after.isOpen).toBe(true);
145+
expect(after.activeSurfaceId).toBe("files");
146+
expect(after.surfaces).toEqual([
147+
{ kind: "files", id: "files", ...(folderTrail === undefined ? {} : { folderTrail }) },
148+
]);
149+
expect(openPreview).not.toHaveBeenCalled();
150+
} finally {
151+
unhost?.();
152+
}
153+
},
154+
);
65155

66156
it("does not reopen workspace tabs without an available project", async () => {
67157
const options = {
68158
openPreview: vi.fn(),
69159
workspaceAvailable: false,
70160
};
71161
for (const surface of [
72-
{ kind: "files", id: "files" },
162+
{ kind: "files", id: "files", folderTrail: "apps/web/src" },
73163
{
74164
kind: "file",
75165
id: "file:src/app.ts",
76166
relativePath: "src/app.ts",
77167
revealLine: null,
78168
revealRequestId: 0,
79169
},
170+
{
171+
kind: "file",
172+
id: "file:apps",
173+
relativePath: "apps",
174+
revealLine: null,
175+
revealRequestId: 1,
176+
folderTrail: "apps/web/src",
177+
},
80178
] as const) {
81179
expect(await reopenClosedView({ kind: "panel-tab", threadRef, surface }, options)).toBe(
82180
false,
Collapse file

‎apps/web/src/reopenClosedView.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/reopenClosedView.ts
+19-1Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import type { ClosedView, ClosedViewEntry } from "./closedViewStore";
55
import type { PullRequestListPreferences } from "./components/pullRequest/pullRequestListPreferences";
66
import { openPreviewSession } from "./components/preview/openPreviewSession";
77
import {
8+
rightPanelHostRef,
89
type RightPanelSurface,
10+
selectThreadRightPanelState,
911
type ThreadRightPanelState,
1012
useRightPanelStore,
1113
} from "./rightPanelStore";
@@ -125,8 +127,24 @@ export async function reopenClosedView(
125127
break;
126128
case "file":
127129
if (surface.attachment) panels.openAttachment(ref, surface.attachment);
128-
else panels.openFile(ref, surface.relativePath, surface.revealLine ?? undefined);
130+
else {
131+
panels.openFile(ref, surface.relativePath, surface.revealLine ?? undefined);
132+
if (typeof surface.folderTrail === "string") {
133+
panels.navigateFolder(ref, surface.id, surface.relativePath, surface.folderTrail);
134+
}
135+
}
136+
break;
137+
case "files": {
138+
const rootAlreadyExists = selectThreadRightPanelState(
139+
panels.byThreadKey,
140+
rightPanelHostRef(ref),
141+
).surfaces.some((current) => current.kind === "files");
142+
panels.open(ref, "files");
143+
if (!rootAlreadyExists && typeof surface.folderTrail === "string") {
144+
panels.navigateFolder(ref, surface.id, "", surface.folderTrail);
145+
}
129146
break;
147+
}
130148
case "device":
131149
if (surface.target) {
132150
panels.openDevice(ref, surface.target);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.