Add MetaOrCtrl-1 through 9 tab navigation
This commit is contained in:
parent
051a84686f
commit
738d449bea
2 changed files with 47 additions and 4 deletions
|
@ -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.
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue