feat(keymap): bind ⌘↓ to Jump to Source in the diff viewer on macOS (#2341)

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 <[email protected]>
Цей коміт міститься в:
ntbang0901таNguyenBang authored and GitHub committed 2026-11-09 20:08:01 +08:00
1 джерело e44a3af310
коміт d02aae2280
3 files changed
+45 -2

No files matched your search

+41
Переглянути файл
@@ -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(<DiffEditor input={input} />);
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(<DiffEditor input={input} />);
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", () => {
+2
Переглянути файл
@@ -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"]],
+2 -2
Переглянути файл
@@ -323,10 +323,10 @@ export const intellijMacos: Record<string, string[]> = {
"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"],