fix(editor): don't carry untitled tabs to the Welcome screen (#4264)

Untitled tabs were carried when Close Project returned to Welcome, after the leave guard had asked about them, so a draft discarded with Don't Save reopened as an empty focused tab. Closing to Welcome now drops them; in-place switches still carry them. Fixes #4173.
This commit is contained in:
l0ng-ai
2026-11-18 19:11:22 +08:00
committed by GitHub
parent ffdb5d74f2
commit 21f1e2bbb4
2 changed files with 16 additions and 1 deletions
+2 -1
View File
@@ -395,10 +395,11 @@ export class EditorController implements SlotHost {
// Untitled buffers belong to the window, not a project: their tabs
// survive the switch (the backend carries them into the new
// registry) and their slots rebuild against the carried documents.
// Closing to Welcome drops them; the leave guard already asked about them.
const carriedUntitled: Tab[] = [];
let carriedActive: string | null = null;
const cs = useTabs.getState();
for (const pane of Object.values(cs.panes)) {
for (const pane of root || s.lightEdit ? Object.values(cs.panes) : []) {
for (const tab of pane.tabs) {
if (isUntitledUri(tab.input.path ?? "")) {
carriedUntitled.push(tab);
+14
View File
@@ -15,6 +15,7 @@ const { serializeSession } = await import("./model/session");
const { useDocMeta } = await import("./model/document");
const { save } = await import("@/platform/dialog");
const editorKinds = await import("@/workbench/contributions");
const { useProject } = await import("@/platform/project");
let ctrl: InstanceType<typeof EditorController> | null = null;
let backend: MemoryBackend;
@@ -158,6 +159,19 @@ describe("untitled editor input", () => {
expect([...backend.files.keys()]).toEqual(["/p/main.rs"]);
});
it("follows the window into another project but not to the Welcome screen", async () => {
const project = (root: string) => ({ root, name: root, trusted: true, isGit: false, settings: {} }) as never;
try {
await ctrl!.openUntitled({ focus: false });
useProject.setState({ project: project("/a") });
expect(activeTab().input.kind).toBe("untitled");
useProject.setState({ project: null });
expect(Object.values(useTabs.getState().panes).flatMap((p) => p.tabs)).toEqual([]);
} finally {
useProject.setState({ project: null });
}
});
it("reuses the buffer for a re-opened untitled name and shares it across tabs", async () => {
const info = await backend.openUntitled(null);
const twice = await backend.openUntitled("untitled:Untitled-1");