Don't open the item context menu on a library section header

In a grouped cross-library view, right-clicking a library header row opened the
item context menu (acting on the current selection, or showing stray options
with none). Library headers aren't items, so ignore the right-click.
This commit is contained in:
Dan Stillman 2026-06-16 12:27:00 -04:00
parent 2e41d080dd
commit bd606f76e7
2 changed files with 39 additions and 1 deletions

View file

@ -3445,6 +3445,11 @@ var ZoteroPane = new function () {
* Show context menu once it's ready
*/
this.onItemsContextMenuOpen = async function (event, x, y) {
// Library section headers (in a grouped cross-library view) aren't items, so
// don't show the item context menu when one is right-clicked
if (event.target?.closest?.('.library-header-row')) {
return;
}
await ZoteroPane.buildItemContextMenu();
x = x || event.screenX;
y = y || event.screenY;

View file

@ -1137,7 +1137,40 @@ describe("ZoteroPane", function () {
await selectLibrary(win);
await group.eraseTx();
});
it("shouldn't open the item context menu on a library header row", async function () {
let group = await createGroup();
let c1 = await createDataObject('collection');
let c2 = await createDataObject('collection', { libraryID: group.libraryID });
await createDataObject('item', { collections: [c1.id] });
await createDataObject('item', { libraryID: group.libraryID, collections: [c2.id] });
// Cross-library multiple-collection selection -> grouped view with headers
await zp.collectionsView.expandLibrary(group.libraryID);
let cv = zp.collectionsView;
await cv.selectByID("C" + c1.id);
await waitForItemsLoad(win);
cv.selection.toggleSelect(cv.getRowIndexByID("C" + c2.id));
await zp.onCollectionSelected();
await zp.itemsView.waitForLoad();
let headerRow = zp.itemsView.getRowIndexByID("L" + Zotero.Libraries.userLibraryID);
let headerNode = win.document.getElementById(`${zp.itemsView.id}-row-${headerRow}`);
assert.isTrue(headerNode.classList.contains('library-header-row'));
let spy = sinon.spy(zp, 'buildItemContextMenu');
try {
await zp.onItemsContextMenuOpen({ target: headerNode, screenX: 0, screenY: 0 });
assert.isFalse(spy.called, "Context menu shouldn't be built for a header row");
}
finally {
spy.restore();
}
await selectLibrary(win);
await group.eraseTx();
});
it("should show “Export Note…” for standalone file attachment with note", async function () {
var item1 = await importFileAttachment('test.png');
item1.setNote('<p>Foo</p>');