From ed24cce4a1aaa0d78a0e2ec0be6ab003d6ccb876 Mon Sep 17 00:00:00 2001 From: Tom Najdek Date: Mon, 12 May 2025 16:41:19 +0200 Subject: [PATCH] Fix custom trash header persisting after items are restored or deleted. Fixes #5279. This was due to a logic bug in `getCurrentPane()`, which returned the wrong pane, causing the incorrect one to be updated. --- chrome/content/zotero/elements/itemPane.js | 2 +- test/tests/itemPaneTest.js | 24 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/elements/itemPane.js b/chrome/content/zotero/elements/itemPane.js index 32e9ae0ebf..895b0548f1 100644 --- a/chrome/content/zotero/elements/itemPane.js +++ b/chrome/content/zotero/elements/itemPane.js @@ -539,7 +539,7 @@ if (!mode) { // Guess a mode from the current data // Only annotation items selected - if (this.data.every(item => item.isAnnotation())) { + if (this.data.length > 0 && this.data.every(item => item.isAnnotation())) { mode = "annotations"; } // No/multiple objects are selected OR selected object is a trashed collection/search diff --git a/test/tests/itemPaneTest.js b/test/tests/itemPaneTest.js index 106e6fae0c..80ea4f5b01 100644 --- a/test/tests/itemPaneTest.js +++ b/test/tests/itemPaneTest.js @@ -209,6 +209,30 @@ describe("Item pane", function () { assert.isFalse(doc.querySelector('item-pane-header .title').hidden); assert.isFalse(doc.querySelector('item-pane-header .creator-year').hidden); }); + + it("should update custom header for items in the trash", async function () { + var item1 = await createDataObject('item', { deleted: true }); + var item2 = await createDataObject('item', { deleted: true }); + + await selectTrash(win); + await ZoteroPane.selectItems([item1.id, item2.id]); + await waitForFrame(); + + let restoreButton = win.document.querySelector('#zotero-item-message .custom-head .item-restore-button'); + assert.exists(restoreButton); + assert.exists(win.document.querySelector('#zotero-item-message .custom-head .item-delete-button')); + + await restoreButton.click(); + let ids = await waitForItemEvent('modify'); + assert.equal(ids.length, 2); + await waitForFrame(); + + assert.notExists(win.document.querySelector('#zotero-item-message .custom-head .item-restore-button')); + + await item1.eraseTx(); + await item2.eraseTx(); + await selectLibrary(win); + }); }); describe("Info pane", function () {