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
This commit is contained in:
Bogdan Abaev 2025-12-17 14:22:36 -08:00 • committed by Adomas Ven
parent ead0924a79
commit be8c64b2bf

View file

@ -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;