Skip to content

The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.

fix(editor): navigate on force click instead of opening macOS Look Up (#1515)

lleviathebff5d1134698
diff --git a/src/editor/lsp/navigation.ts b/src/editor/lsp/navigation.ts
index 6b27c97e0..16ec470ca 100644
--- a/src/editor/lsp/navigation.ts
+++ b/src/editor/lsp/navigation.ts
@@ -402,9 +402,21 @@ const linkPlugin = ViewPlugin.fromClass(
private probeTimer: ReturnType<typeof setTimeout> | undefined;
constructor(readonly view: EditorView) {
// Window-wide, so ⌘/Ctrl over an unfocused editor underlines too; released anywhere clears it.
- this.off = onNavigationModifier((held) => {
+ const offModifier = onNavigationModifier((held) => {
if (!held || this.last) this.show(held);
});
+ // IDEA's macOS "Force touch" shortcut: a force click navigates like ⌘-click
+ // (the keyboard dispatcher keeps the system Look Up popover away).
+ const onForceDown = (e: Event) => {
+ const m = e as MouseEvent;
+ if (m.metaKey || m.ctrlKey || m.altKey || m.shiftKey) return;
+ if (navigateFromPointer(view, m)) m.preventDefault();
+ };
+ view.contentDOM.addEventListener("webkitmouseforcedown", onForceDown);
+ this.off = () => {
+ offModifier();
+ view.contentDOM.removeEventListener("webkitmouseforcedown", onForceDown);
+ };
}
destroy() {
this.off();
@@ -530,18 +542,24 @@ const linkPlugin = ViewPlugin.fromClass(
}
// IDEA parity: middle button navigates on a plain click, without the modifier.
if (e.button === 1 ? e.metaKey || e.ctrlKey || e.altKey || e.shiftKey : !isNavigationGesture(e)) return false;
- const pos = view.posAtCoords({ x: e.clientX, y: e.clientY }, false);
- if (pos == null) return false;
+ if (!navigateFromPointer(view, e)) return false;
e.preventDefault();
- view.dispatch({ selection: EditorSelection.cursor(pos), effects: setLink.of(null) });
- view.focus();
- void gotoTargets(view, "definition", pos);
return true;
},
},
},
);
+/** Puts the caret under the pointer and goes to the declaration there, like a ⌘/Ctrl-click. */
+function navigateFromPointer(view: EditorView, e: MouseEvent): boolean {
+ const pos = view.posAtCoords({ x: e.clientX, y: e.clientY }, false);
+ if (pos == null) return false;
+ view.dispatch({ selection: EditorSelection.cursor(pos), effects: setLink.of(null) });
+ view.focus();
+ void gotoTargets(view, "definition", pos);
+ return true;
+}
+
// ---------------------------------------------------------------------------
// Document highlights
diff --git a/src/editor/lsp/navigationMouse.test.ts b/src/editor/lsp/navigationMouse.test.ts
index 5ec3b9d53..b44ec67d4 100644
--- a/src/editor/lsp/navigationMouse.test.ts
+++ b/src/editor/lsp/navigationMouse.test.ts
@@ -170,3 +170,32 @@ describe("mouse navigation", () => {
}
});
});
+
+describe("force click (macOS trackpad)", () => {
+ function force(type: string, init: MouseEventInit = {}) {
+ const event = new MouseEvent(type, { bubbles: true, cancelable: true, ...init });
+ view.contentDOM.dispatchEvent(event);
+ return event;
+ }
+
+ it("keeps the system Look Up popover away", () => {
+ expect(force("webkitmouseforcewillbegin").defaultPrevented).toBe(true);
+ });
+
+ it("goes to the declaration under the pointer, like ⌘-click", async () => {
+ const event = force("webkitmouseforcedown");
+ await vi.waitFor(() => expect(openFile).toHaveBeenCalledOnce());
+ expect(lspGoto).toHaveBeenCalledExactlyOnceWith(1, { line: 0, col: 9 }, "definition");
+ expect(view.state.selection.main.head).toBe(9);
+ expect(event.defaultPrevented).toBe(true);
+ });
+
+ it.each([{ metaKey: true }, { altKey: true }, { ctrlKey: true }, { shiftKey: true }])(
+ "leaves a modified force click to the click gesture: %o",
+ async (mods) => {
+ force("webkitmouseforcedown", mods);
+ await Promise.resolve();
+ expect(lspGoto).not.toHaveBeenCalled();
+ },
+ );
+});
diff --git a/src/platform/keymap.ts b/src/platform/keymap.ts
index f7d3f1617..7af4fb6a2 100644
--- a/src/platform/keymap.ts
+++ b/src/platform/keymap.ts
@@ -642,6 +642,9 @@ export function installKeyboardDispatcher(
e.stopPropagation();
};
+ /** macOS force click: no system Look Up popover over IDE text; the editor navigates instead. */
+ const onForceWillBegin = (e: Event) => e.preventDefault();
+
const onBlur = () => {
reset();
resetTap();
@@ -652,6 +655,7 @@ export function installKeyboardDispatcher(
target.addEventListener("mousedown", onMouseDown, true);
target.addEventListener("mouseup", onMouseRelease, true);
target.addEventListener("auxclick", onMouseRelease, true);
+ target.addEventListener("webkitmouseforcewillbegin", onForceWillBegin, true);
target.addEventListener("blur", onBlur);
return () => {
target.removeEventListener("keydown", onKeyDown, true);
@@ -659,6 +663,7 @@ export function installKeyboardDispatcher(
target.removeEventListener("mousedown", onMouseDown, true);
target.removeEventListener("mouseup", onMouseRelease, true);
target.removeEventListener("auxclick", onMouseRelease, true);
+ target.removeEventListener("webkitmouseforcewillbegin", onForceWillBegin, true);
target.removeEventListener("blur", onBlur);
};
}