From 8b083aa426e3dcb5080bab5c56696ad8f24a79fc Mon Sep 17 00:00:00 2001 From: windingwind <33902321+windingwind@users.noreply.github.com> Date: Fri, 10 May 2024 10:59:42 +0800 Subject: [PATCH] Fix context pane unnecessary update Fixes #4029 --- chrome/content/zotero/elements/contextPane.js | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/chrome/content/zotero/elements/contextPane.js b/chrome/content/zotero/elements/contextPane.js index 4dacbd1425..23c67ca956 100644 --- a/chrome/content/zotero/elements/contextPane.js +++ b/chrome/content/zotero/elements/contextPane.js @@ -97,33 +97,35 @@ _handleItemUpdate(action, type, ids, extraData) { // Update, remove or re-create item panes - for (let itemDetails of Array.from(this._itemPaneDeck.children)) { - let item = itemDetails.item; - let tabID = itemDetails.dataset.tabId; - if (!item) { - this._removeItemContext(tabID); - } - else if (item.parentID != itemDetails.parentID) { - this._removeItemContext(tabID); - this._addItemContext(tabID, item.itemID); + if (action === 'modify') { + for (let itemDetails of Array.from(this._itemPaneDeck.children)) { + let tabID = itemDetails.tabID; + let item = Zotero.Items.get(Zotero_Tabs._getTab(tabID)?.tab.data.itemID); + if ((item.parentID || itemDetails.parentID) + && item.parentID !== itemDetails.parentID) { + this._removeItemContext(tabID); + this._addItemContext(tabID, item.itemID); + } } } // Update notes lists for affected libraries - let libraryIDs = []; - for (let id of ids) { - let item = Zotero.Items.get(id); - if (item && (item.isNote() || item.isRegularItem())) { - libraryIDs.push(item.libraryID); + if (['add', 'delete', 'modify'].includes(action)) { + let libraryIDs = []; + for (let id of ids) { + let item = Zotero.Items.get(id); + if (item && (item.isNote() || item.isRegularItem())) { + libraryIDs.push(item.libraryID); + } + else if (action == 'delete') { + libraryIDs.push(extraData[id].libraryID); + } } - else if (action == 'delete') { - libraryIDs.push(extraData[id].libraryID); - } - } - for (let context of Array.from(this._notesPaneDeck.children)) { - if (libraryIDs.includes(context.libraryID)) { - context.affectedIDs = new Set([...context.affectedIDs, ...ids]); - context.update(); + for (let context of Array.from(this._notesPaneDeck.children)) { + if (libraryIDs.includes(context.libraryID)) { + context.affectedIDs = new Set([...context.affectedIDs, ...ids]); + context.update(); + } } } }