From d02aae2280e1ac81e26c809f27e05b3950698bd5 Mon Sep 17 00:00:00 2001 From: ntbang0901 <121003585+ntbang0901@users.noreply.github.com> Date: Mon, 9 Nov 2026 19:08:01 +0700 Subject: [PATCH] =?UTF-8?q?feat(keymap):=20bind=20=E2=8C=98=E2=86=93=20to?= =?UTF-8?q?=20Jump=20to=20Source=20in=20the=20diff=20viewer=20on=20macOS?= =?UTF-8?q?=20(#2341)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit IDEA's Diff.OpenInEditor copies EditSource's shortcuts, which the Mac OS X 10.5+ keymap binds to F4 and ⌘↓. The IntelliJ (macOS) preset only had F4 for diff.jumpToSource, which macOS often takes for itself. The binding is scoped by diffEditorFocus, so ⌘↓ still moves to the document end in other editors. Closes #2292 Co-authored-by: NguyenBang --- .../vcs/__tests__/diffToolbar.test.tsx | 41 +++++++++++++++++++ src/platform/keymaps/ideaParity.test.ts | 2 + src/platform/keymaps/intellij-macos.ts | 4 +- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/features/vcs/__tests__/diffToolbar.test.tsx b/src/features/vcs/__tests__/diffToolbar.test.tsx index df2357084..719e6988a 100644 --- a/src/features/vcs/__tests__/diffToolbar.test.tsx +++ b/src/features/vcs/__tests__/diffToolbar.test.tsx @@ -50,6 +50,9 @@ import { DiffEditorTab } from "../diff-editor-tab"; import { diffInput, withChain, type DiffData } from "../diffInput"; import { useToolWindowLayout } from "@/workbench/toolwindows/store"; import { useProject } from "@/platform/project"; +import { applyKeymapSettings, installKeyboardDispatcher, useKeymap } from "@/platform/keymap"; +import { setContext } from "@/platform/context"; +import { registerCompareActions } from "../compare"; /** Git Log opens a commit's file: both sides are revisions. */ const input = { @@ -456,6 +459,44 @@ describe("Jump to Source of a revision diff", () => { render(); expect(await jumpFrom(0, 2)).toEqual(["/p/a.ts", { selection: { line: 5, col: 1 }, focus: true }]); }); + + it("jumps on ⌘↓ in the IntelliJ macOS keymap only while a diff pane has focus", async () => { + setUp(); + const keymap = useKeymap.getState(); + applyKeymapSettings("intellij-macos", {}); + const unregister = registerCompareActions(); + const uninstall = installKeyboardDispatcher(window); + const cmdDown = (target: EventTarget) => { + const e = new KeyboardEvent("keydown", { + key: "ArrowDown", + code: "ArrowDown", + metaKey: true, + bubbles: true, + cancelable: true, + }); + target.dispatchEvent(e); + return e; + }; + try { + render(); + const v = await pane(1); + v.dispatch({ selection: { anchor: v.state.doc.line(3).from + 1 } }); + v.contentDOM.dispatchEvent(new FocusEvent("focus")); + v.contentDOM.dispatchEvent(new FocusEvent("focusin", { bubbles: true })); + expect(cmdDown(v.contentDOM).defaultPrevented).toBe(true); + await waitFor(() => expect(openFile).toHaveBeenCalled()); + expect(openFile.mock.calls[0]).toEqual(["/p/a.ts", { selection: { line: 3, col: 1 }, focus: true }]); + + setContext("diffEditorFocus", false); + const plain = document.body.appendChild(document.createElement("div")); + expect(cmdDown(plain).defaultPrevented).toBe(false); + plain.remove(); + } finally { + uninstall(); + unregister(); + useKeymap.setState(keymap); + } + }); }); describe("Unified Revert", () => { diff --git a/src/platform/keymaps/ideaParity.test.ts b/src/platform/keymaps/ideaParity.test.ts index 939a86e0a..bb100d5be 100644 --- a/src/platform/keymaps/ideaParity.test.ts +++ b/src/platform/keymaps/ideaParity.test.ts @@ -28,6 +28,8 @@ describe("IDEA keymap parity", () => { ["code.quickDefinition", ["Alt+Space", "Meta+Y"], ["Ctrl+Shift+I"]], ["editor.copyPathReference", ["Meta+Shift+C"], ["Ctrl+Shift+C"]], ["project.open", ["F4", "Meta+Down"], ["F4"]], + // Diff.OpenInEditor copies EditSource's shortcuts. + ["diff.jumpToSource", ["F4", "Meta+Down"], ["F4"]], ["project.delete", ["Delete", "Backspace", "Meta+Backspace"], ["Delete"]], ["file.reloadFromDisk", ["Meta+Alt+Y"], ["Ctrl+Alt+Y"]], ["project.reloadFromDisk", ["Meta+Alt+Y"], ["Ctrl+Alt+Y"]], diff --git a/src/platform/keymaps/intellij-macos.ts b/src/platform/keymaps/intellij-macos.ts index cbb3f9b06..045ba6626 100644 --- a/src/platform/keymaps/intellij-macos.ts +++ b/src/platform/keymaps/intellij-macos.ts @@ -323,10 +323,10 @@ export const intellijMacos: Record = { "view.resetZoom": ["Ctrl+Alt+0"], "editor.increaseFontSize": ["Alt+Shift+."], "editor.decreaseFontSize": ["Alt+Shift+,"], - // Diff viewer (after Debug: F7 / ⇧F7 / F4 there win while a diff is focused) + // Diff viewer (after Debug: F7 / ⇧F7 / F4 / ⌘↓ there win while a diff is focused) "diff.nextDifference": ["F7"], "diff.prevDifference": ["Shift+F7"], - "diff.jumpToSource": ["F4"], + "diff.jumpToSource": ["F4", "Meta+Down"], "diff.applyLeftSide": ["Ctrl+Meta+Right"], "diff.applyRightSide": ["Ctrl+Meta+Left"], "diff.nextFile": ["Ctrl+Shift+Right"],