From d231a033082995c8785885c89e8686b90ee146b5 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 28 Jun 2021 12:07:49 +0100 Subject: [PATCH 1/6] Move tab navigation above from and document checks This ensure tab navigation functions are always available throughout Zotero. --- chrome/content/zotero/zoteroPane.js | 38 ++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 5e74c4c842..75aec3cccc 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -549,7 +549,23 @@ var ZoteroPane = new function() return; } } - + + // Tab navigation + // TODO: Select across tabs without selecting with Ctrl-Shift, as in Firefox? + let ctrlOnly = event.ctrlKey && !event.metaKey && !event.shiftKey && !event.altKey; + if (ctrlOnly) { + if (event.key == 'PageUp') { + Zotero_Tabs.selectPrev(); + event.preventDefault(); + return; + } + else if (event.key == 'PageDown') { + Zotero_Tabs.selectNext(); + event.preventDefault(); + return; + } + } + try { // Ignore keystrokes outside of Zotero pane if (!(event.originalTarget.ownerDocument instanceof XULDocument)) { @@ -564,24 +580,8 @@ var ZoteroPane = new function() event.preventDefault(); return; } - - if (from == 'zotero-pane') { - // Tab navigation - // TODO: Select across tabs without selecting with Ctrl-Shift, as in Firefox? - let ctrlOnly = event.ctrlKey && !event.metaKey && !event.shiftKey && !event.altKey; - if (ctrlOnly) { - if (event.key == 'PageUp') { - Zotero_Tabs.selectPrev(); - event.preventDefault(); - return; - } - else if (event.key == 'PageDown') { - Zotero_Tabs.selectNext(); - event.preventDefault(); - return; - } - } - + + if (from == 'zotero-pane') { // Highlight collections containing selected items // // We use Control (17) on Windows because Alt triggers the menubar; From 9afc6e8f47d096023b63addc3dcc91bbf1a23241 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Sun, 11 Jul 2021 01:29:42 +0100 Subject: [PATCH 2/6] Tweak existing tab navigation style --- chrome/content/zotero/zoteroPane.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 75aec3cccc..4efcdca626 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -550,10 +550,9 @@ var ZoteroPane = new function() } } - // Tab navigation + // Tab navigation: Ctrl-PageUp / PageDown // TODO: Select across tabs without selecting with Ctrl-Shift, as in Firefox? - let ctrlOnly = event.ctrlKey && !event.metaKey && !event.shiftKey && !event.altKey; - if (ctrlOnly) { + if (event.ctrlKey && !event.metaKey && !event.shiftKey && !event.altKey) { if (event.key == 'PageUp') { Zotero_Tabs.selectPrev(); event.preventDefault(); From 28b34bb95830389663145ed661736451a94e5643 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Sun, 11 Jul 2021 01:32:12 +0100 Subject: [PATCH 3/6] Add stop propagation to existing tab navigation --- chrome/content/zotero/zoteroPane.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 4efcdca626..f64f579349 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -556,11 +556,13 @@ var ZoteroPane = new function() if (event.key == 'PageUp') { Zotero_Tabs.selectPrev(); event.preventDefault(); + event.stopPropagation(); return; } else if (event.key == 'PageDown') { Zotero_Tabs.selectNext(); event.preventDefault(); + event.stopPropagation(); return; } } From 3a95e2e3036277a196a37791d69332f06848ce2f Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Sun, 11 Jul 2021 01:41:13 +0100 Subject: [PATCH 4/6] Add Cmd-Shift-[ / ] tab navigation on macOS only --- chrome/content/zotero/zoteroPane.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index f64f579349..cf489ec677 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -567,6 +567,26 @@ var ZoteroPane = new function() } } + // Tab navigation: Cmd-Shift-[ / ] + // Common shortcut on macOS, but typically only supported on that platform to match OS + // conventions users expect from other macOS apps. + if (Zotero.isMac) { + if (event.metaKey && event.shiftKey && !event.altKey && !event.ctrlKey) { + if (event.key == '[') { + Zotero_Tabs.selectPrev(); + event.preventDefault(); + event.stopPropagation(); + return; + } + else if (event.key == ']') { + Zotero_Tabs.selectNext(); + event.preventDefault(); + event.stopPropagation(); + return; + } + } + } + try { // Ignore keystrokes outside of Zotero pane if (!(event.originalTarget.ownerDocument instanceof XULDocument)) { From 051a84686f333266526c1564621a1bcde199f26c Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Sun, 11 Jul 2021 01:50:11 +0100 Subject: [PATCH 5/6] Add Ctrl-Tab / Ctrl-Shift-Tab tab navigation --- chrome/content/zotero/zoteroPane.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index cf489ec677..0749bd5f5d 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -587,6 +587,22 @@ var ZoteroPane = new function() } } + // Tab navigation: Ctrl-Tab / Ctrl-Shift-Tab + if (event.ctrlKey && !event.altKey && !event.metaKey && event.key == 'Tab') { + if (event.shiftKey) { + Zotero_Tabs.selectPrev(); + event.preventDefault(); + event.stopPropagation(); + return; + } + else { + Zotero_Tabs.selectNext(); + event.preventDefault(); + event.stopPropagation(); + return; + } + } + try { // Ignore keystrokes outside of Zotero pane if (!(event.originalTarget.ownerDocument instanceof XULDocument)) { From 738d449bea35ca0feee286c8ccbce66ac8edcdce Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Sun, 11 Jul 2021 02:25:12 +0100 Subject: [PATCH 6/6] Add MetaOrCtrl-1 through 9 tab navigation --- chrome/content/zotero/tabs.js | 17 +++++++++++++++ chrome/content/zotero/zoteroPane.js | 34 +++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 4 deletions(-) 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)) {