qf: fix breakage with unloaded tab (#5347)

Properly load all item data for items opened in tabs
to account for the fact that they can belong to
libraries that are not yet loaded.

Similar fix as in 4421de63de
This commit is contained in:
abaevbog 2025-06-19 21:19:17 -07:00 committed by GitHub
parent 4cc52ec928
commit 3aef6cddcb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -656,13 +656,22 @@ var Zotero_QuickFormat = new function () {
}).map(t => t.data.itemID);
if (!itemIDs.length) return [];
let items = itemIDs.map((itemID) => {
let item = Zotero.Items.get(itemID);
// Fetch top-most items and load necessary data, in case tabs belong to an unloaded library
let items = [];
for (let itemID of itemIDs) {
let item = await Zotero.Items.getAsync(itemID);
if (item && item.parentItemID) {
itemID = item.parentItemID;
item = await Zotero.Items.getAsync(item.parentItemID);
}
return Zotero.Cite.getItem(itemID);
});
// Ignore tabs from libraries that are not specified
if (io.filterLibraryIDs) {
let itemInLibrary = io.filterLibraryIDs.some(id => id === item.libraryID);
if (!itemInLibrary) continue;
}
items.push(item);
}
await Zotero.Items.loadDataTypes(items);
let matchedItems = new Set(items);
if (options.searchString) {
Zotero.debug("QuickFormat: Searching open tabs");