Merge pull request #2121 from jryans/more-tab-shortcuts
Add more tab navigation shortcuts
This commit is contained in:
commit
4db5b4a23f
2 changed files with 103 additions and 23 deletions
|
@ -230,6 +230,23 @@ var Zotero_Tabs = new function () {
|
|||
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.
|
||||
* Only used on Windows and Linux. On macOS, the tab bar is always shown.
|
||||
|
|
|
@ -535,12 +535,13 @@ var ZoteroPane = new function()
|
|||
* Trigger actions based on keyboard shortcuts
|
||||
*/
|
||||
function handleKeyDown(event, from) {
|
||||
// Close current tab
|
||||
if (event.key == 'w') {
|
||||
let close = Zotero.isMac
|
||||
const metaOrCtrlOnly = Zotero.isMac
|
||||
? (event.metaKey && !event.shiftKey && !event.ctrlKey && !event.altKey)
|
||||
: (event.ctrlKey && !event.shiftKey && !event.altKey);
|
||||
if (close) {
|
||||
|
||||
// Close current tab
|
||||
if (event.key == 'w') {
|
||||
if (metaOrCtrlOnly) {
|
||||
if (Zotero_Tabs.selectedIndex > 0) {
|
||||
Zotero_Tabs.close();
|
||||
event.preventDefault();
|
||||
|
@ -550,6 +551,84 @@ var ZoteroPane = new function()
|
|||
}
|
||||
}
|
||||
|
||||
// Tab navigation: Ctrl-PageUp / PageDown
|
||||
// TODO: Select across tabs without selecting with Ctrl-Shift, as in Firefox?
|
||||
if (event.ctrlKey && !event.metaKey && !event.shiftKey && !event.altKey) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
// 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)) {
|
||||
|
@ -566,22 +645,6 @@ var ZoteroPane = new function()
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// Highlight collections containing selected items
|
||||
//
|
||||
// We use Control (17) on Windows because Alt triggers the menubar;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue