From 7f993a152800020a7900346c790287af51ac52f7 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Thu, 2 May 2024 14:11:32 -0400 Subject: [PATCH] Tab shortcuts: Use event.code for better keyboard layout compat --- chrome/content/zotero/zoteroPane.js | 42 ++++++++++++++++------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index c901861ef6..03f78d4bce 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -64,6 +64,8 @@ var ZoteroPane = new function() const modifierIsNotShift = ev => ev.getModifierState("Meta") || ev.getModifierState("Alt") || ev.getModifierState("Control") || ev.getModifierState("OS"); + + const TAB_NUMBER_CODE_RE = /^(?:Numpad|Digit)([0-9])$/; var self = this, _loaded = false, _madeVisible = false, @@ -984,24 +986,28 @@ var ZoteroPane = new function() // 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. if (cmdOrCtrlOnly) { - switch (event.key) { - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - Zotero_Tabs.jump(parseInt(event.key) - 1); - event.preventDefault(); - event.stopPropagation(); - return; - case '9': - Zotero_Tabs.selectLast(); - event.preventDefault(); - event.stopPropagation(); - return; + let tabNumberMatch = event.code.match(TAB_NUMBER_CODE_RE); + if (tabNumberMatch) { + let tabNumber = tabNumberMatch[1]; + switch (tabNumber) { + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + Zotero_Tabs.jump(parseInt(tabNumber) - 1); + event.preventDefault(); + event.stopPropagation(); + return; + case '9': + Zotero_Tabs.selectLast(); + event.preventDefault(); + event.stopPropagation(); + return; + } } } }