diff --git a/src/features/settings/__tests__/behavior.test.ts b/src/features/settings/__tests__/behavior.test.ts index 15dd3cc721..eb80ff9821 100644 --- a/src/features/settings/__tests__/behavior.test.ts +++ b/src/features/settings/__tests__/behavior.test.ts @@ -200,4 +200,5 @@ describe("appearance & behavior settings", () => { it("loads an old attach setting as ask", () => { expect(validateGeneralExtras({ openProjectIn: "attach" }).openProjectIn).toBe("ask"); + expect(validateGeneralExtras({ openProjectIn: "tab" }).openProjectIn).toBe("tab"); }); diff --git a/src/features/settings/model/behaviorSchema.ts b/src/features/settings/model/behaviorSchema.ts index bdcd038fce..8b28783258 100644 --- a/src/features/settings/model/behaviorSchema.ts +++ b/src/features/settings/model/behaviorSchema.ts @@ -10,7 +10,7 @@ import { ZOOM_LIMITS } from "@/platform/zoom"; import { validateIconThemeOptionsMap } from "@/platform/iconThemeOptions"; export type Antialiasing = "subpixel" | "greyscale" | "none"; -export type OpenProjectIn = "ask" | "new" | "same"; +export type OpenProjectIn = "ask" | "new" | "same" | "tab"; export type NotificationDisplay = "balloon" | "sticky" | "none"; export type NavigationBarPosition = "top" | "statusBar" | "hidden"; export type BackgroundImageFill = "scale" | "plain" | "tile"; @@ -306,7 +306,7 @@ export function validateGeneralExtras(raw: unknown): GeneralExtras { const d = DEFAULT_GENERAL_EXTRAS; const df = obj(g.dateFormat); return { - openProjectIn: oneOf(g.openProjectIn, ["ask", "new", "same"] as const, d.openProjectIn), + openProjectIn: oneOf(g.openProjectIn, ["ask", "new", "same", "tab"] as const, d.openProjectIn), updateSource: oneOf(g.updateSource, ["auto", "github", "cnb"] as const, d.updateSource), autoCheckUpdates: bool(g.autoCheckUpdates, d.autoCheckUpdates), showWhatsNewAfterUpdate: bool(g.showWhatsNewAfterUpdate, d.showWhatsNewAfterUpdate), diff --git a/src/features/settings/pages/behavior.tsx b/src/features/settings/pages/behavior.tsx index e2e5508291..25cb430910 100644 --- a/src/features/settings/pages/behavior.tsx +++ b/src/features/settings/pages/behavior.tsx @@ -575,6 +575,7 @@ function ToolWindowsGrid() { const OPEN_IN: Array<{ value: OpenProjectIn; label: string }> = [ { value: "new", label: "New window" }, { value: "same", label: "Current window" }, + { value: "tab", label: "New tab in current window" }, { value: "ask", label: "Ask" }, ]; diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index d7743ebbbb..f7b345b5e1 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -2632,6 +2632,7 @@ "Hot reload on save failed: {0}": "Hot reload on save failed: {0}", "Projects can be opened in a new window, replace the current project, be attached to the already opened projects, or open as a new tab of this window.\nHow would you like to open \"{name}\"?": "Projects can be opened in a new window, replace the current project, be attached to the already opened projects, or open as a new tab of this window.\nHow would you like to open \"{name}\"?", "New Tab": "New Tab", + "New tab in current window": "New tab in current window", "Show Only Widgets": "Show Only Widgets", "Update failed": "Update failed", "Updating branches": "Updating branches", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 18d79dac53..f65fe281fe 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -1911,6 +1911,7 @@ "New name": "新名称", "New terminal sessions run the interpreter's virtualenv activate script.": "新的终端会话会运行解释器的 virtualenv 激活脚本。", "New window": "新窗口", + "New tab in current window": "当前窗口的新标签页", "New…": "新建…", "Next Bookmark": "下一个书签", "Next Change": "下一个更改", diff --git a/src/workbench/projectWindow.test.ts b/src/workbench/projectWindow.test.ts index d9cc367861..bbaf256a01 100644 --- a/src/workbench/projectWindow.test.ts +++ b/src/workbench/projectWindow.test.ts @@ -23,7 +23,8 @@ beforeEach(() => { lightEdit: false, }); }); -it.each(["attach", "tab"] as const)("offers %s for this open without remembering it", async (button) => { +it("offers attach for this open without remembering it", async () => { + const button = "attach"; vi.mocked(ask).mockResolvedValue({ button, checked: true }); expect(await chooseProjectWindow("B")).toBe(button); const prompt = vi.mocked(ask).mock.calls[0]![0]; @@ -49,8 +50,18 @@ it("treats a stored attach policy as ask", () => { useProject.setState({ settings: { general: { openProjectIn: "attach" } } } as never); expect(openPolicy()).toBe("ask"); }); -it.each(["new", "same"] as const)("remembers %s", async (mode) => { +it.each(["new", "same", "tab"] as const)("remembers %s", async (mode) => { vi.mocked(ask).mockResolvedValue({ button: mode, checked: true }); await chooseProjectWindow("B"); expect(commands.settingsSet).toHaveBeenCalledWith("global", "general.openProjectIn", JSON.stringify(mode)); }); + +it("opens a project tab by policy, or a new window when this one can't take one", async () => { + useProject.setState({ settings: { general: { openProjectIn: "tab" } } } as never); + expect(openPolicy()).toBe("tab"); + expect(await chooseProjectWindow("B")).toBe("tab"); + expect(await chooseProjectWindow("remote", false)).toBe("new"); + useProject.setState({ project: null, lightEdit: true }); + expect(await chooseProjectWindow("B")).toBe("new"); + expect(ask).not.toHaveBeenCalled(); +}); diff --git a/src/workbench/projectWindow.ts b/src/workbench/projectWindow.ts index d36bfaaff6..3b4f67834a 100644 --- a/src/workbench/projectWindow.ts +++ b/src/workbench/projectWindow.ts @@ -7,9 +7,9 @@ import { ask } from "./messages"; import { maybeEditorService } from "./contributions"; /** "Open project in": `new` | `same` | `ask`. */ -export function openPolicy(): "ask" | "new" | "same" { +export function openPolicy(): "ask" | "new" | "same" | "tab" { const v = useProject.getState().settings?.general?.openProjectIn; - return v === "new" || v === "same" ? v : "ask"; + return v === "new" || v === "same" || v === "tab" ? v : "ask"; } /** @@ -26,6 +26,8 @@ export async function chooseProjectWindow( // Both ways of keeping this window's project: a workspace folder, or a project tab of this window. const canAdd = allowAttach && !!project && !isRemoteWindow(); const mode = openPolicy(); + // A project tab needs this window's project beside it; without one, a new window is the closest. + if (mode === "tab") return canAdd ? "tab" : "new"; if (mode !== "ask") return mode; const r = await ask({ title: t("app.window.askTitle"), @@ -46,9 +48,9 @@ export async function chooseProjectWindow( ], checkbox: t("app.window.askRemember"), }); - // "Attach" and "New Tab" are one-off: "Open project in" has no value for them, so Don't ask again ignores both. + // "Attach" is one-off, as in IDEA: "Open project in" has no value for it, so Don't ask again ignores it. if (r.button !== "same" && r.button !== "new" && r.button !== "attach" && r.button !== "tab") return null; - if (r.checked && (r.button === "same" || r.button === "new")) { + if (r.checked && r.button !== "attach") { try { useProject.setState({ settings: await call(commands.settingsSet("global", "general.openProjectIn", JSON.stringify(r.button))),