Remove collectionTreeRow from the plugin menu context

Menu plugins reading it acted on one arbitrary row of the selection.
Reading it now throws and names collectionTreeRows, which the context
has already provided since multi-collection selection landed.

The context now copies property descriptors rather than values, since
copying values would evaluate the throwing collectionTreeRow getter for
every menu.
This commit is contained in:
Dan Stillman 2026-07-29 10:56:11 -04:00
parent 783da0e66e
commit dc6d55a137
3 changed files with 15 additions and 9 deletions

View file

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

View file

@ -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",

View file

@ -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",
]
},