diff --git a/crates/ide-core/src/workflow_settings.rs b/crates/ide-core/src/workflow_settings.rs index 12a2886d5..c7c8c92cb 100644 --- a/crates/ide-core/src/workflow_settings.rs +++ b/crates/ide-core/src/workflow_settings.rs @@ -11,6 +11,8 @@ use std::collections::BTreeMap; pub struct VcsSettings { /// Colour folders that contain changed files (project tree, tabs). pub show_dirty_directories: bool, + /// Diffs the user opens show in an editor tab; off, in a separate window. + pub diff_as_editor_tab: bool, /// Stop file history (Show History) after `history_limit` commits. pub limit_history: bool, pub history_limit: u32, @@ -55,6 +57,7 @@ impl Default for VcsSettings { Self { // IDEA's VcsConfiguration.SHOW_DIRTY_RECURSIVELY is off by default. show_dirty_directories: false, + diff_as_editor_tab: true, limit_history: true, history_limit: 1000, git: GitSettings::default(), diff --git a/src/bindings.ts b/src/bindings.ts index a4594021f..693617f6b 100644 --- a/src/bindings.ts +++ b/src/bindings.ts @@ -12428,6 +12428,8 @@ export type VcsRoot = { export type VcsSettings = { /** Colour folders that contain changed files (project tree, tabs). */ showDirtyDirectories?: boolean, + /** Diffs the user opens show in an editor tab; off, in a separate window. */ + diffAsEditorTab?: boolean, /** Stop file history (Show History) after `history_limit` commits. */ limitHistory?: boolean, historyLimit?: number, diff --git a/src/features/settings/pages/vcs.tsx b/src/features/settings/pages/vcs.tsx index c539e89b7..78ea200f9 100644 --- a/src/features/settings/pages/vcs.tsx +++ b/src/features/settings/pages/vcs.tsx @@ -752,6 +752,12 @@ export const VCS_PAGES: PageSpec[] = [ key: "vcs.showDirtyDirectories", label: "Highlight directories that contain modified files in the Project tree", }, + { + kind: "toggle", + key: "vcs.diffAsEditorTab", + label: "Open diff as editor tab", + hint: "When off, diffs you open (changes, history, Compare) show in a separate window.", + }, { kind: "select", key: "vcs.confirmation.onPatchCreated", diff --git a/src/features/vcs/__tests__/modalDiffWindow.test.ts b/src/features/vcs/__tests__/modalDiffWindow.test.ts index 3a402560d..127ecf16e 100644 --- a/src/features/vcs/__tests__/modalDiffWindow.test.ts +++ b/src/features/vcs/__tests__/modalDiffWindow.test.ts @@ -8,6 +8,8 @@ import { showChangesDiff, type LogChange } from "../logChanges"; const front = vi.hoisted(() => ({ diff: vi.fn(), merge: vi.fn() })); vi.mock("../diffDialog", () => ({ openDiffDialog: front.diff, openMergeDiffDialog: front.merge })); +const separate = vi.hoisted(() => vi.fn()); +vi.mock("../DiffWindow", () => ({ showDiffWindow: separate })); /** Editor tabs the diffs open in (openDiff → the editor service). */ const openInput = vi.fn(async () => undefined); @@ -75,3 +77,15 @@ it("opens a commit's file diff in the preview tab with the non-modal interface", await showChangesDiff([file]); expect(openInput).toHaveBeenLastCalledWith(expect.objectContaining({ kind: "diff" }), { preview: true, focus: true }); }); + +it("opens diffs in a separate window when Open diff as editor tab is off", async () => { + useProject.setState({ settings: { vcs: { diffAsEditorTab: false } } as Settings }); + await getAction("diff.compareTexts")!.run({ arg: texts, ctx: {} }); + expect(separate).toHaveBeenCalledWith(expect.objectContaining({ path: "/p/a.ts" }), expect.any(Function)); + expect(openInput).not.toHaveBeenCalled(); + // The modal commit interface still shows them in its front window. + useProject.setState({ settings: { vcs: { diffAsEditorTab: false, commit: { nonModal: false } } } as Settings }); + await getAction("diff.compareTexts")!.run({ arg: texts, ctx: {} }); + expect(front.diff).toHaveBeenCalledTimes(1); + expect(separate).toHaveBeenCalledTimes(1); +}); diff --git a/src/features/vcs/diffInput.ts b/src/features/vcs/diffInput.ts index 057ea33a8..f7f6be5db 100644 --- a/src/features/vcs/diffInput.ts +++ b/src/features/vcs/diffInput.ts @@ -209,7 +209,12 @@ export const opensDiffOnActivate = () => { * (`vcs.openDiff`, with review comments) call openDiff directly. */ export async function openVcsDiff(data: DiffData, opts: { preview?: boolean; focus?: boolean } = {}) { - if (!vcsDiffInFront()) return openDiff(data, opts); + if (!vcsDiffInFront()) { + // Settings › Version Control › Confirmation: "Open diff as editor tab" off. + if (workflowSettings().vcs.diffAsEditorTab || combinedOf(data)) return openDiff(data, opts); + const { showDiffWindow } = await import("./DiffWindow"); + return showDiffWindow(data, () => void openDiff(data, opts)); + } const { openDiffDialog } = await import("./diffDialog"); openDiffDialog(data); } diff --git a/src/platform/clientSettings.ts b/src/platform/clientSettings.ts index 9541ccc7a..5073d4cbe 100644 --- a/src/platform/clientSettings.ts +++ b/src/platform/clientSettings.ts @@ -94,6 +94,7 @@ export const CLIENT_SETTINGS_KEYS = [ "run.pinTabs", "externalDiff", "vcs.showDirtyDirectories", + "vcs.diffAsEditorTab", "vcs.git.inlineBlame", "vcs.git.inlineBlameClickable", "vcs.git.showBranchInProjectView", diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index bfee64cd1..b3fbfa679 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -1,4 +1,6 @@ { + "Open diff as editor tab": "Open diff as editor tab", + "When off, diffs you open (changes, history, Compare) show in a separate window.": "When off, diffs you open (changes, history, Compare) show in a separate window.", "Plain-text word lists (one word per line) or Hunspell .dic files; a .dic with its .aff beside it also accepts the inflected forms and compounds its rules allow. Relative paths resolve against the project root, ~/ against the home folder.": "Plain-text word lists (one word per line) or Hunspell .dic files; a .dic with its .aff beside it also accepts the inflected forms and compounds its rules allow. Relative paths resolve against the project root, ~/ against the home folder.", "Trust Folder": "Trust Folder", "No files selected": "No files selected", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index d9e16d6f3..c8fc16a0a 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -1,4 +1,6 @@ { + "Open diff as editor tab": "以编辑器标签页打开差异", + "When off, diffs you open (changes, history, Compare) show in a separate window.": "关闭后,打开的差异(更改、历史记录、比较)会显示在单独的窗口中。", "Plain-text word lists (one word per line) or Hunspell .dic files; a .dic with its .aff beside it also accepts the inflected forms and compounds its rules allow. Relative paths resolve against the project root, ~/ against the home folder.": "纯文本单词列表(每行一个词)或 Hunspell .dic 文件;旁边有同名 .aff 的 .dic 还会接受其规则允许的变形和复合词。相对路径基于项目根目录解析,~/ 表示主目录。", "MCP server instructions": "MCP 服务器说明", "MCP tools (deferred)": "MCP 工具(延迟加载)", diff --git a/src/platform/workflowSettings.ts b/src/platform/workflowSettings.ts index 3769e3622..46e810e90 100644 --- a/src/platform/workflowSettings.ts +++ b/src/platform/workflowSettings.ts @@ -76,6 +76,8 @@ export interface CommitSettingsValid { export interface VcsSettingsValid { showDirtyDirectories: boolean; + /** Off: diffs the user opens show in a separate window. */ + diffAsEditorTab: boolean; limitHistory: boolean; historyLimit: number; git: GitSettingsValid; @@ -274,6 +276,7 @@ export const DEFAULT_WORKFLOW: WorkflowSettings = { vcs: { // IDEA's VcsConfiguration.SHOW_DIRTY_RECURSIVELY is off by default. showDirtyDirectories: false, + diffAsEditorTab: true, limitHistory: true, historyLimit: 1000, git: { @@ -448,6 +451,7 @@ export function validateVcs(raw: unknown): VcsSettingsValid { const confirm = ["ask", "silently", "never"] as const; return { showDirtyDirectories: bool(v.showDirtyDirectories, d.showDirtyDirectories), + diffAsEditorTab: bool(v.diffAsEditorTab, d.diffAsEditorTab), limitHistory: bool(v.limitHistory, d.limitHistory), historyLimit: num(v.historyLimit, d.historyLimit, L.historyLimit, true), git: {