From 40ae2e32462e55fd1048888c267e7ecd76838c5d Mon Sep 17 00:00:00 2001
From: Martynas Bagdonas <git.martynas@gmail.com>
Date: Thu, 18 Aug 2022 10:19:07 +0300
Subject: [PATCH] Fix navigation to annotation when opening an unloaded PDF
 reader tab Regression from 142e3b09

---
 chrome/content/zotero/tabs.js         | 4 ++--
 chrome/content/zotero/xpcom/reader.js | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/chrome/content/zotero/tabs.js b/chrome/content/zotero/tabs.js
index 7410bcf333..d3ff2a38a2 100644
--- a/chrome/content/zotero/tabs.js
+++ b/chrome/content/zotero/tabs.js
@@ -337,7 +337,7 @@ var Zotero_Tabs = new function () {
 	 * @param {String} id
 	 * @param {Boolean} reopening
 	 */
-	this.select = function (id, reopening) {
+	this.select = function (id, reopening, options) {
 		var { tab, tabIndex } = this._getTab(id);
 		if (!tab || tab.id === this._selectedID) {
 			return;
@@ -348,7 +348,7 @@ var Zotero_Tabs = new function () {
 		}
 		if (tab.type === 'reader-unloaded') {
 			this.close(tab.id);
-			Zotero.Reader.open(tab.data.itemID, null, {
+			Zotero.Reader.open(tab.data.itemID, options && options.location, {
 				tabID: tab.id,
 				title: tab.title,
 				tabIndex,
diff --git a/chrome/content/zotero/xpcom/reader.js b/chrome/content/zotero/xpcom/reader.js
index 546ad7e4d7..616f667b6a 100644
--- a/chrome/content/zotero/xpcom/reader.js
+++ b/chrome/content/zotero/xpcom/reader.js
@@ -1383,7 +1383,7 @@ class Reader {
 			if (win) {
 				let existingTabID = win.Zotero_Tabs.getTabIDByItemID(itemID);
 				if (existingTabID) {
-					win.Zotero_Tabs.select(existingTabID);
+					win.Zotero_Tabs.select(existingTabID, false, { location });
 					return;
 				}
 			}