fix collection highlight regression

- Bring back un-highlighting of collections on keydown if any other
control key besides Ctrl/Options is pressed (with better comments).
It fixes regression after 527fa5b12f
where if one presses, for example, Ctrl-Shift-A to copy an item,
collection highlighting would scroll the collection tree for no reason.

- To decrease the chance of collection highlighting being activated when
it is not intended, only highlight collections when the itemTree is focused
This commit is contained in:
Bogdan Abaev 2024-03-04 13:09:03 -05:00 committed by Adomas Ven
parent 95cfc4be13
commit e07ac555af

View file

@ -1051,16 +1051,17 @@ var ZoteroPane = new function()
// //
// We use Control (17) on Windows and Linux because Alt triggers the menubar; // We use Control (17) on Windows and Linux because Alt triggers the menubar;
// On Mac, we use Option (18) // On Mac, we use Option (18)
let enableHighlight = !event.shiftKey && !event.metaKey; let enableHighlight = false;
if (Zotero.isMac) { if (Zotero.isMac) {
enableHighlight = event.key == "Alt" && !event.ctrlKey; enableHighlight = !event.shiftKey && !event.metaKey && event.key == "Alt" && !event.ctrlKey;
} }
else { else {
enableHighlight = event.key == "Control" && !event.altKey; enableHighlight = !event.shiftKey && !event.metaKey && event.key == "Control" && !event.altKey;
} }
// Do not interfere with Control-C/Control-V shortcuts let isItemTreeFocused = document.activeElement.id == "item-tree-main-default";
let inputFocused = ["input", "textarea"].includes(document.activeElement.tagName); // Only highlight collections when itemTree is focused to try to avoid
if (enableHighlight && !inputFocused) { // conflicts with other shortcuts
if (enableHighlight && isItemTreeFocused) {
// On windows, the event is re-triggered multiple times // On windows, the event is re-triggered multiple times
// for as long as Control is held. // for as long as Control is held.
// To account for that, stop if a highlight timer already exists. // To account for that, stop if a highlight timer already exists.
@ -1074,6 +1075,15 @@ var ZoteroPane = new function()
notify: ZoteroPane_Local.setHighlightedRowsCallback notify: ZoteroPane_Local.setHighlightedRowsCallback
}, 225, Components.interfaces.nsITimer.TYPE_ONE_SHOT); }, 225, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
} }
// If anything but Ctlr/Options was pressed, most likely a different shortcut using Ctlr/Options
// is being used (e.g. Ctrl-Shift-A on windows). In that case, stop highlighting
else if ((Zotero.isMac && event.altKey) || (!Zotero.isMac && event.ctrlKey)) {
if (this.highlightTimer) {
this.highlightTimer.cancel();
this.highlightTimer = null;
}
ZoteroPane.collectionsView.setHighlightedRows();
}
} }
} }