Move the checkmark to the activated target in createMenuForTarget()

The target menu isn't rebuilt between openings, so the checkmark stayed
on the target the menu was built with. In the New Collection dialog,
whose menu belongs to a menulist, that would leave two checkmarks if you
clicked a different collection and then reopened the menu.
This commit is contained in:
Dan Stillman 2026-08-28 11:27:17 -04:00
parent 07745b634b
commit eb33fa5835

View file

@ -1821,6 +1821,24 @@ Zotero.Utilities.Internal = {
return menu;
}
// The menu isn't rebuilt between openings, so move the checkmark to the target
// that's activated. A <menulist> marks the item clicked in its own popup as
// selected, drawing a checkmark of its own, and can't clear it when the next
// pick is in a submenu, so clear that too.
function _setCurrentTarget(target) {
if (!currentTarget) {
return;
}
for (let menuitem of elem.querySelectorAll('menuitem[checked], menuitem[selected]')) {
menuitem.removeAttribute('checked');
menuitem.removeAttribute('selected');
}
let menuitem = elem.querySelector(`menuitem[value="${target.treeViewID}"]`);
if (menuitem) {
menuitem.setAttribute('checked', 'true');
}
}
function _appendTarget(target, parent) {
let collections = target.objectType == 'collection'
? Zotero.Collections.getByParent(target.id)
@ -1834,7 +1852,10 @@ Zotero.Utilities.Internal = {
return null;
}
let command = event => clickAction(event, target);
let command = (event) => {
_setCurrentTarget(target);
clickAction(event, target);
};
let imageSrc = target.treeViewImage;
// Create menuitem for library or collection itself, to be placed either directly in