Skip to content

Commit 8ccdac8

Browse files
committed
Implement Accel and use it as default to support ⌘ on Mac
1 parent 218e85d commit 8ccdac8

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ over the underlined code to see a more detailed message
2727

2828
### Jump to Definition
2929

30-
Use the context menu entry, or <kbd>Ctrl</kbd> + :computer_mouse: to jump to definitions (customizable); use <kbd>Alt</kbd> + <kbd>o</kbd> to jump back
30+
Use the context menu entry, or <kbd>Ctrl</kbd> + :computer_mouse: to jump to definitions (<kbd>⌘</kbd> on Mac; customizable); use <kbd>Alt</kbd> + <kbd>o</kbd> to jump back
3131

3232
![jump](https://raw.githubusercontent.com/krassowski/jupyterlab-lsp/master/examples/screenshots/jump_to_definition.png)
3333

packages/jupyterlab-lsp/schema/jump_to.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"modifierKey": {
99
"title": "Modifier key",
1010
"type": "string",
11-
"enum": ["Alt", "Control", "Shift", "Meta", "AltGraph"],
12-
"default": "Control",
13-
"description": "Keyboard key which needs to be pressed with click to jump. The allowed keys are Alt, Control, Shift, and AltGraph. Linux user: Meta key is also supported. Safari users: Meta key is also supported, AltGraph is not supported. To see which physical keys are mapped, visit: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/getModifierState"
11+
"enum": ["Alt", "Control", "Shift", "Meta", "AltGraph", "Accel"],
12+
"default": "Accel",
13+
"description": "Keyboard key which needs to be pressed with click to jump. The allowed keys are Alt, Control, Shift, Accel, and AltGraph. Accel corresponds to Control or Meta (⌘ Command on Mac). Linux user: Meta key is also supported. Safari users: Meta key is also supported, AltGraph is not supported. To see which physical keys are mapped, visit: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/getModifierState"
1414
}
1515
},
1616
"jupyter.lab.shortcuts": [

packages/jupyterlab-lsp/src/utils.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,20 @@ export function until_ready(
3434
});
3535
}
3636

37+
export type ModifierKey =
38+
| 'Shift'
39+
| 'Alt'
40+
| 'AltGraph'
41+
| 'Control'
42+
| 'Meta'
43+
| 'Accel';
44+
3745
/**
38-
* TODO: this is slightly modified copy paste from jupyterlab-go-to-definition/editors/codemirror/extension.ts;
46+
* CodeMirror-proof implementation of event.getModifierState()
3947
*/
4048
export function getModifierState(
4149
event: MouseEvent | KeyboardEvent,
42-
modifierKey: string
50+
modifierKey: ModifierKey
4351
): boolean {
4452
// Note: Safari does not support getModifierState on MouseEvent, see:
4553
// https://github.com/krassowski/jupyterlab-go-to-definition/issues/3
@@ -59,12 +67,19 @@ export function getModifierState(
5967
case 'Alt':
6068
value = event.altKey || key == 'Alt';
6169
break;
70+
case 'AltGraph':
71+
value = key == 'AltGraph';
72+
break;
6273
case 'Control':
6374
value = event.ctrlKey || key == 'Control';
6475
break;
6576
case 'Meta':
6677
value = event.metaKey || key == 'Meta';
6778
break;
79+
case 'Accel':
80+
value =
81+
event.metaKey || key == 'Meta' || event.ctrlKey || key == 'Control';
82+
break;
6883
}
6984

7085
if (event.getModifierState !== undefined) {

0 commit comments

Comments
 (0)