From 90cc53361bbde78deeb547b02a458fc71755d669 Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Thu, 28 Oct 2021 11:22:48 +0300 Subject: [PATCH] Refocus to the last focused node when switching back to Zotero Pane tab --- chrome/content/zotero/standalone/standalone.js | 3 --- chrome/content/zotero/tabs.js | 11 +++++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/chrome/content/zotero/standalone/standalone.js b/chrome/content/zotero/standalone/standalone.js index f7f47270c2..0661d99b1e 100644 --- a/chrome/content/zotero/standalone/standalone.js +++ b/chrome/content/zotero/standalone/standalone.js @@ -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 diff --git a/chrome/content/zotero/tabs.js b/chrome/content/zotero/tabs.js index 2998863695..228be4f3c6 100644 --- a/chrome/content/zotero/tabs.js +++ b/chrome/content/zotero/tabs.js @@ -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; + } }; /**