Tab shortcuts: Use event.code for better keyboard layout compat

This commit is contained in:
Abe Jellinek 2024-05-02 14:11:32 -04:00 committed by Dan Stillman
parent 13c96c6520
commit 7f993a1528

View file

@ -65,6 +65,8 @@ var ZoteroPane = new function()
const modifierIsNotShift = ev => ev.getModifierState("Meta") || ev.getModifierState("Alt") const modifierIsNotShift = ev => ev.getModifierState("Meta") || ev.getModifierState("Alt")
|| ev.getModifierState("Control") || ev.getModifierState("OS"); || ev.getModifierState("Control") || ev.getModifierState("OS");
const TAB_NUMBER_CODE_RE = /^(?:Numpad|Digit)([0-9])$/;
var self = this, var self = this,
_loaded = false, _madeVisible = false, _loaded = false, _madeVisible = false,
titlebarcolorState, titleState, observerService, titlebarcolorState, titleState, observerService,
@ -984,24 +986,28 @@ var ZoteroPane = new function()
// Jump to tab N (or to the last tab if there are less than N tabs) // Jump to tab N (or to the last tab if there are less than N tabs)
// CmdOrCtrl-9 is specially defined to jump to the last tab no matter how many there are. // CmdOrCtrl-9 is specially defined to jump to the last tab no matter how many there are.
if (cmdOrCtrlOnly) { if (cmdOrCtrlOnly) {
switch (event.key) { let tabNumberMatch = event.code.match(TAB_NUMBER_CODE_RE);
case '1': if (tabNumberMatch) {
case '2': let tabNumber = tabNumberMatch[1];
case '3': switch (tabNumber) {
case '4': case '1':
case '5': case '2':
case '6': case '3':
case '7': case '4':
case '8': case '5':
Zotero_Tabs.jump(parseInt(event.key) - 1); case '6':
event.preventDefault(); case '7':
event.stopPropagation(); case '8':
return; Zotero_Tabs.jump(parseInt(tabNumber) - 1);
case '9': event.preventDefault();
Zotero_Tabs.selectLast(); event.stopPropagation();
event.preventDefault(); return;
event.stopPropagation(); case '9':
return; Zotero_Tabs.selectLast();
event.preventDefault();
event.stopPropagation();
return;
}
} }
} }
} }