From be8c64b2bf92ac9b81b7d7c78ed1a8677bca7953 Mon Sep 17 00:00:00 2001 From: Bogdan Abaev Date: Wed, 17 Dec 2025 14:22:36 -0800 Subject: [PATCH] citation dlg: fix hang when main window is closed When fetching open tabs for the citation dialog, fall back to the last saved session state if the main window is closed. Session state was already being updated when zotero pane is closed. Fixes: #5661 --- .../integration/citationDialog/searchHandler.mjs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/integration/citationDialog/searchHandler.mjs b/chrome/content/zotero/integration/citationDialog/searchHandler.mjs index 0505e03f7e..402ab4667d 100644 --- a/chrome/content/zotero/integration/citationDialog/searchHandler.mjs +++ b/chrome/content/zotero/integration/citationDialog/searchHandler.mjs @@ -273,8 +273,18 @@ export class CitationDialogSearchHandler { async _getReaderOpenItems() { if (this.isCitingNotes) return []; + let tabs = []; let win = Zotero.getMainWindow(); - let tabs = win.Zotero_Tabs.getState(); + // If the main window is open, use it to get open tabs + if (win) { + tabs = win.Zotero_Tabs.getState(); + } + // If the main window is closed, try to get tabs from the last saved session + else { + let mainWindowLastState = Zotero.Session.state.windows.find(w => w.type === 'pane'); + if (!mainWindowLastState) return []; + tabs = mainWindowLastState.tabs; + } let itemIDs = tabs.filter(t => t.type === 'reader').sort((a, b) => { // Sort selected tab first if (a.selected) return -1;