From 21f1e2bbb475b7a5c97c11d6434194f54d2ca427 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Wed, 18 Nov 2026 19:11:22 +0800 Subject: [PATCH] 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. --- src/editor/core/controller.ts | 3 ++- src/editor/core/untitled.test.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/editor/core/controller.ts b/src/editor/core/controller.ts index be56cf4e9..ad6d3ac21 100644 --- a/src/editor/core/controller.ts +++ b/src/editor/core/controller.ts @@ -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); diff --git a/src/editor/core/untitled.test.ts b/src/editor/core/untitled.test.ts index 6bb1374ab..93f81cc69 100644 --- a/src/editor/core/untitled.test.ts +++ b/src/editor/core/untitled.test.ts @@ -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 | 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");