Tab bar: Change tab with Ctrl-Page-Up/Page-Down
This commit is contained in:
parent
a47d7e4d9c
commit
2ca1618627
3 changed files with 58 additions and 2 deletions
|
@ -33,6 +33,33 @@ const TabBar = forwardRef(function (props, ref) {
|
|||
const [selectedIndex, setSelectedIndex] = useState(0);
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
get selectedIndex() {
|
||||
return selectedIndex;
|
||||
},
|
||||
|
||||
selectLeft() {
|
||||
var newIndex = selectedIndex - 1;
|
||||
if (newIndex < 0) {
|
||||
newIndex = tabs.length + newIndex;
|
||||
}
|
||||
setSelectedIndex(newIndex);
|
||||
},
|
||||
|
||||
selectRight() {
|
||||
var newIndex = selectedIndex + 1;
|
||||
if (newIndex >= tabs.length) {
|
||||
newIndex = newIndex - tabs.length;
|
||||
}
|
||||
setSelectedIndex(newIndex);
|
||||
},
|
||||
|
||||
select(index) {
|
||||
if (index > tabs.length - 1) {
|
||||
throw new Error("Tab index out of bounds");
|
||||
}
|
||||
setSelectedIndex(index);
|
||||
},
|
||||
|
||||
addTab({ title, type }) {
|
||||
var newTabs = [...tabs];
|
||||
newTabs.push({ title, type });
|
||||
|
@ -49,7 +76,7 @@ const TabBar = forwardRef(function (props, ref) {
|
|||
return newTab;
|
||||
});
|
||||
setTabs(newTabs);
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
@ -44,6 +44,7 @@ var Zotero_Tabs = new function () {
|
|||
type: 'library'
|
||||
}
|
||||
];
|
||||
this._selectedIndex = 0;
|
||||
|
||||
this.init = function () {
|
||||
ReactDOM.render(
|
||||
|
@ -59,6 +60,21 @@ var Zotero_Tabs = new function () {
|
|||
};
|
||||
|
||||
|
||||
this.selectLeft = function () {
|
||||
this._tabBarRef.current.selectLeft();
|
||||
};
|
||||
|
||||
|
||||
this.selectRight = function () {
|
||||
this._tabBarRef.current.selectRight();
|
||||
};
|
||||
|
||||
|
||||
this.select = function (index) {
|
||||
this._tabBarRef.current.select(index);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @return {Element} - The element created in the deck
|
||||
*/
|
||||
|
@ -85,7 +101,7 @@ var Zotero_Tabs = new function () {
|
|||
|
||||
this.rename = function (title, index) {
|
||||
if (index === undefined) {
|
||||
index = this.deck.selectedIndex;
|
||||
index = this._selectedIndex;
|
||||
}
|
||||
this._tabs[index].title = title;
|
||||
this._tabBarRef.current.renameTab(title, index);
|
||||
|
@ -93,6 +109,7 @@ var Zotero_Tabs = new function () {
|
|||
|
||||
|
||||
this._onTabSelected = function (index) {
|
||||
this._selectedIndex = index;
|
||||
this.deck.selectedIndex = index;
|
||||
};
|
||||
|
||||
|
|
|
@ -628,6 +628,18 @@ var ZoteroPane = new function()
|
|||
|
||||
var command = Zotero.Keys.getCommand(event.key);
|
||||
|
||||
let ctrlOnly = event.ctrlKey && !event.metaKey && !event.shiftKey && !event.altKey;
|
||||
if (ctrlOnly) {
|
||||
if (event.key == 'PageUp') {
|
||||
Zotero_Tabs.selectLeft();
|
||||
}
|
||||
else if (event.key == 'PageDown') {
|
||||
Zotero_Tabs.selectRight();
|
||||
}
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
if (from == 'zotero-collections-tree') {
|
||||
if ((event.keyCode == event.DOM_VK_BACK_SPACE && Zotero.isMac) ||
|
||||
event.keyCode == event.DOM_VK_DELETE) {
|
||||
|
|
Loading…
Reference in a new issue