Compare commits

...
Author SHA1 Message Date
l0ng-ai 46ecca3427 feat(workbench): open projects in a new tab of the current window by default
"Open project in" gets "New tab in current window", and Don't ask again in the Open Project
dialog now remembers New Tab as well. With it set, opening another project adds a project tab
to this window without asking. A window without a project of its own, or a remote project,
opens in a new window instead. Attach stays a one-off choice.
2026-11-20 13:25:11 +08:00
7 changed files with 25 additions and 8 deletions

No files matched your search

@@ -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");
});
@@ -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),
+1
View File
@@ -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" },
];
+1
View File
@@ -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",
+1
View File
@@ -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": "下一个更改",
+13 -2
View File
@@ -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();
});
+6 -4
View File
@@ -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))),