diff --git a/chrome/content/zotero/tabs.js b/chrome/content/zotero/tabs.js index 1251df334c..064e99ca71 100644 --- a/chrome/content/zotero/tabs.js +++ b/chrome/content/zotero/tabs.js @@ -229,6 +229,23 @@ var Zotero_Tabs = new function () { var { tabIndex } = this._getTab(this._selectedID); this.select((this._tabs[tabIndex + 1] || this._tabs[0]).id); }; + + /** + * Select the last tab + */ + this.selectLast = function () { + this.select(this._tabs[this._tabs.length - 1].id); + }; + + /** + * Jump to the tab at a particular index. If the index points beyond the array, jump to the last + * tab. + * + * @param {Integer} index + */ + this.jump = function(index) { + this.select(this._tabs[Math.min(index, this._tabs.length - 1)].id); + }; /** * Update state of the tab bar. diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 0749bd5f5d..bc810bbeac 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -535,12 +535,13 @@ var ZoteroPane = new function() * Trigger actions based on keyboard shortcuts */ function handleKeyDown(event, from) { + const metaOrCtrlOnly = Zotero.isMac + ? (event.metaKey && !event.shiftKey && !event.ctrlKey && !event.altKey) + : (event.ctrlKey && !event.shiftKey && !event.altKey); + // Close current tab if (event.key == 'w') { - let close = Zotero.isMac - ? (event.metaKey && !event.shiftKey && !event.ctrlKey && !event.altKey) - : (event.ctrlKey && !event.shiftKey && !event.altKey); - if (close) { + if (metaOrCtrlOnly) { if (Zotero_Tabs.selectedIndex > 0) { Zotero_Tabs.close(); event.preventDefault(); @@ -603,6 +604,31 @@ var ZoteroPane = new function() } } + // Tab navigation: MetaOrCtrl-1 through 9 + // Jump to tab N (or to the last tab if there are less than N tabs) + // MetaOrCtrl-9 is specially defined to jump to the last tab no matter how many there are. + if (metaOrCtrlOnly) { + 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; + } + } + try { // Ignore keystrokes outside of Zotero pane if (!(event.originalTarget.ownerDocument instanceof XULDocument)) {