diff --git a/chrome/content/zotero/xpcom/pluginAPI/menuManager.js b/chrome/content/zotero/xpcom/pluginAPI/menuManager.js index 2cc9a8af9a..93474bd398 100644 --- a/chrome/content/zotero/xpcom/pluginAPI/menuManager.js +++ b/chrome/content/zotero/xpcom/pluginAPI/menuManager.js @@ -632,8 +632,16 @@ _menuElem.style.setProperty("--custom-menu-icon-dark", `url(${darkIcon || icon})`); }, }; + // ZoteroPane's menu contexts define a collectionTreeRow property that + // throws when read, so copy descriptors rather than values, which would + // evaluate it every time a menu is built let wrappedGetContext = () => { - return Object.assign({}, defaultContext, getContext ? getContext() : {}); + let context = {}; + Object.defineProperties(context, Object.getOwnPropertyDescriptors(defaultContext)); + if (getContext) { + Object.defineProperties(context, Object.getOwnPropertyDescriptors(getContext())); + } + return context; }; // Add hooks diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 76ff8ffd69..e3d4fd659d 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -4113,9 +4113,9 @@ var ZoteroPane = new function () { "main/library/collection", { getContext: () => ({ - // collectionTreeRow is the first selected row, kept for - // backward compatibility; collectionTreeRows is the full selection - collectionTreeRow: collectionTreeRows[0], + get collectionTreeRow() { + throw new Error("collectionTreeRow was removed -- use collectionTreeRows"); + }, collectionTreeRows, tabType: "library", tabSubType: undefined, @@ -4659,9 +4659,9 @@ var ZoteroPane = new function () { "main/library/item", { getContext: () => ({ - // collectionTreeRow is the first selected row, kept for - // backward compatibility; collectionTreeRows is the full selection - collectionTreeRow: collectionTreeRows[0], + get collectionTreeRow() { + throw new Error("collectionTreeRow was removed -- use collectionTreeRows"); + }, collectionTreeRows, items, tabType: "library", diff --git a/test/tests/pluginAPITest.js b/test/tests/pluginAPITest.js index 04bf2651f9..70db8ca94b 100644 --- a/test/tests/pluginAPITest.js +++ b/test/tests/pluginAPITest.js @@ -943,7 +943,6 @@ describe("Plugin API", function () { contextKeys: [ ...defaultContextKeys, "items", - "collectionTreeRow", "collectionTreeRows", ] }, @@ -954,7 +953,6 @@ describe("Plugin API", function () { }, contextKeys: [ ...defaultContextKeys, - "collectionTreeRow", "collectionTreeRows", ] },