Refocus to the last focused node when switching back to Zotero Pane tab

This commit is contained in:
Martynas Bagdonas 2021-10-28 11:22:48 +03:00
parent be49786668
commit 90cc53361b
2 changed files with 11 additions and 3 deletions

View file

@ -54,9 +54,6 @@ const ZoteroStandalone = new function() {
{
notify: async (action, type, ids, extraData) => {
if (action == 'select') {
if (Zotero_Tabs.selectedIndex == 0) {
ZoteroPane.itemsView.focus();
}
// Reader doesn't have tabID yet
setTimeout(async () => {
// Item and other things might not be loaded yet when reopening tabs

View file

@ -295,11 +295,22 @@ var Zotero_Tabs = new function () {
if (!tab || tab.id === this._selectedID) {
return;
}
if (this._selectedID === 'zotero-pane') {
var { tab: selectedTab } = this._getTab(this._selectedID);
selectedTab.lastFocusedElement = document.activeElement;
}
this._prevSelectedID = reopening ? this._selectedID : null;
this._selectedID = id;
this.deck.selectedIndex = Array.from(this.deck.children).findIndex(x => x.id == id);
this._update();
Zotero.Notifier.trigger('select', 'tab', [tab.id], { [tab.id]: { type: tab.type } }, true);
if (tab.id === 'zotero-pane' && tab.lastFocusedElement) {
tab.lastFocusedElement.focus();
if (document.activeElement !== tab.lastFocusedElement) {
ZoteroPane_Local.itemsView.focus();
}
tab.lastFocusedElement = null;
}
};
/**