Skip to content

Commit a08af0a

Browse files
committed
fix #4467 - jupyter/firefox: ctrl-shift-"-" doesn't work
1 parent d4efbde commit a08af0a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/packages/frontend/jupyter/commands.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ export interface KeyboardCommand {
3333
meta?: boolean;
3434
key?: string;
3535
// TODO: key is currently only used for displaying what the shortcut is; however,
36-
// "which" is deprecated and we should switch to using only key!
36+
// "which" is deprecated and we should switch to using only key.
37+
// However, key is also tricky, e.g., key for shift+h is an upper case "H", but
38+
// if you just hit h it is lower case "h", so you can't just switch to using event.key.
3739
// See https://github.com/sagemathinc/cocalc/issues/4020
3840
}
3941

src/packages/frontend/jupyter/keyboard.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ export function evt_to_obj(evt: any, mode: NotebookMode): KeyboardCommand {
5050
if (mode != null) {
5151
obj.mode = mode;
5252
}
53+
if (evt.which == 173) {
54+
// firefox sends 173 for the "-" key but everybody else sends 189
55+
// see https://github.com/sagemathinc/cocalc/issues/4467
56+
// See also https://stackoverflow.com/questions/18177818/why-jquerys-event-which-gives-different-results-in-firefox-and-chrome
57+
// and of course we should rewrite this entire file to use
58+
// evt.key instead of evt.which
59+
evt.which = 189;
60+
}
61+
if (evt.which == 59) {
62+
// firefox sends 59 for the "-" key but everybody else sends 186
63+
evt.which = 186;
64+
}
5365
return obj;
5466
}
5567

0 commit comments

Comments
 (0)