Tab bar: Close current tab with Cmd/Ctrl-w
And use keydown, not keypress, for moving between tabs
This commit is contained in:
parent
9afd509704
commit
b5f7255da2
3 changed files with 52 additions and 18 deletions
|
@ -60,14 +60,14 @@ const TabBar = forwardRef(function (props, ref) {
|
||||||
setSelectedIndex(index);
|
setSelectedIndex(index);
|
||||||
},
|
},
|
||||||
|
|
||||||
addTab({ title, type }) {
|
add({ title, type }) {
|
||||||
var newTabs = [...tabs];
|
var newTabs = [...tabs];
|
||||||
newTabs.push({ title, type });
|
newTabs.push({ title, type });
|
||||||
setTabs(newTabs);
|
setTabs(newTabs);
|
||||||
setSelectedIndex(newTabs.length - 1);
|
setSelectedIndex(newTabs.length - 1);
|
||||||
},
|
},
|
||||||
|
|
||||||
renameTab(title, index) {
|
rename(title, index) {
|
||||||
var newTabs = tabs.map((tab, currentIndex) => {
|
var newTabs = tabs.map((tab, currentIndex) => {
|
||||||
let newTab = Object.assign({}, tab);
|
let newTab = Object.assign({}, tab);
|
||||||
if (index == currentIndex) {
|
if (index == currentIndex) {
|
||||||
|
@ -77,6 +77,13 @@ const TabBar = forwardRef(function (props, ref) {
|
||||||
});
|
});
|
||||||
setTabs(newTabs);
|
setTabs(newTabs);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
close(index) {
|
||||||
|
if (index == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
removeTab(index);
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -33,6 +33,10 @@ import TabBar from 'components/tabBar';
|
||||||
var Zotero_Tabs = new function () {
|
var Zotero_Tabs = new function () {
|
||||||
const HTML_NS = 'http://www.w3.org/1999/xhtml';
|
const HTML_NS = 'http://www.w3.org/1999/xhtml';
|
||||||
|
|
||||||
|
Object.defineProperty(this, 'selectedIndex', {
|
||||||
|
get: () => this._selectedIndex
|
||||||
|
});
|
||||||
|
|
||||||
Object.defineProperty(this, 'deck', {
|
Object.defineProperty(this, 'deck', {
|
||||||
get: () => document.getElementById('tabs-deck')
|
get: () => document.getElementById('tabs-deck')
|
||||||
});
|
});
|
||||||
|
@ -79,7 +83,7 @@ var Zotero_Tabs = new function () {
|
||||||
* @return {Element} - The element created in the deck
|
* @return {Element} - The element created in the deck
|
||||||
*/
|
*/
|
||||||
this.add = function ({ title, type, url, index }) {
|
this.add = function ({ title, type, url, index }) {
|
||||||
this._tabBarRef.current.addTab({ title, type });
|
this._tabBarRef.current.add({ title, type });
|
||||||
|
|
||||||
var elem;
|
var elem;
|
||||||
if (url) {
|
if (url) {
|
||||||
|
@ -104,7 +108,15 @@ var Zotero_Tabs = new function () {
|
||||||
index = this._selectedIndex;
|
index = this._selectedIndex;
|
||||||
}
|
}
|
||||||
this._tabs[index].title = title;
|
this._tabs[index].title = title;
|
||||||
this._tabBarRef.current.renameTab(title, index);
|
this._tabBarRef.current.rename(title, index);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
this.close = function (index) {
|
||||||
|
if (index === undefined) {
|
||||||
|
index = this._selectedIndex;
|
||||||
|
}
|
||||||
|
this._tabBarRef.current.close(index);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -542,6 +542,35 @@ var ZoteroPane = new function()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (from == 'zotero-pane') {
|
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.selectLeft();
|
||||||
|
}
|
||||||
|
else if (event.key == 'PageDown') {
|
||||||
|
Zotero_Tabs.selectRight();
|
||||||
|
}
|
||||||
|
event.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 (Zotero_Tabs.selectedIndex > 0) {
|
||||||
|
Zotero_Tabs.close();
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Highlight collections containing selected items
|
// Highlight collections containing selected items
|
||||||
//
|
//
|
||||||
// We use Control (17) on Windows because Alt triggers the menubar;
|
// We use Control (17) on Windows because Alt triggers the menubar;
|
||||||
|
@ -628,20 +657,6 @@ var ZoteroPane = new function()
|
||||||
|
|
||||||
var command = Zotero.Keys.getCommand(event.key);
|
var command = Zotero.Keys.getCommand(event.key);
|
||||||
|
|
||||||
// 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.selectLeft();
|
|
||||||
}
|
|
||||||
else if (event.key == 'PageDown') {
|
|
||||||
Zotero_Tabs.selectRight();
|
|
||||||
}
|
|
||||||
event.preventDefault();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (from == 'zotero-collections-tree') {
|
if (from == 'zotero-collections-tree') {
|
||||||
if ((event.keyCode == event.DOM_VK_BACK_SPACE && Zotero.isMac) ||
|
if ((event.keyCode == event.DOM_VK_BACK_SPACE && Zotero.isMac) ||
|
||||||
event.keyCode == event.DOM_VK_DELETE) {
|
event.keyCode == event.DOM_VK_DELETE) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue