Select existing unloaded tab instead of opening a new one

Fixes #2740
This commit is contained in:
Martynas Bagdonas 2022-08-05 18:22:30 +03:00 committed by Dan Stillman
parent 9190eb8f34
commit 098886bcb6
2 changed files with 16 additions and 0 deletions

View file

@ -84,6 +84,11 @@ var Zotero_Tabs = new function () {
window.Zotero_Tooltip.stop(); window.Zotero_Tooltip.stop();
}; };
this.getTabIDByItemID = function (itemID) {
let tab = this._tabs.find(tab => tab.data && tab.data.itemID === itemID);
return tab && tab.id;
};
this.init = function () { this.init = function () {
ReactDOM.render( ReactDOM.render(
<TabBar <TabBar

View file

@ -1372,6 +1372,17 @@ class Reader {
this.triggerAnnotationsImportCheck(itemID); this.triggerAnnotationsImportCheck(itemID);
let reader; let reader;
if (!allowDuplicate) {
let win = Zotero.getMainWindow();
if (win) {
let existingTabID = win.Zotero_Tabs.getTabIDByItemID(itemID);
if (existingTabID) {
win.Zotero_Tabs.select(existingTabID);
return;
}
}
}
if (openInWindow) { if (openInWindow) {
reader = this._readers.find(r => r._itemID === itemID && (r instanceof ReaderWindow)); reader = this._readers.find(r => r._itemID === itemID && (r instanceof ReaderWindow));
} }