tabs menu updates

- CMD-F will focus the input field
- ArrowLeft/Right keypresses are ignored
- Reset focus index on the focus of the input field
This commit is contained in:
abaevbog 2024-01-24 17:03:13 -05:00 committed by Dan Stillman
parent 69054bea4a
commit f990cb3f4b
2 changed files with 15 additions and 0 deletions

View file

@ -1005,6 +1005,10 @@ var Zotero_Tabs = new function () {
this.refreshTabsMenuList(); this.refreshTabsMenuList();
}; };
this.resetFocusIndex = (_) => {
this._tabsMenuFocusedIndex = 0;
};
/** /**
* Focus on the element in the tabs menu with [tabindex=tabIndex] if given * Focus on the element in the tabs menu with [tabindex=tabIndex] if given
@ -1046,6 +1050,7 @@ var Zotero_Tabs = new function () {
* - ArrowUp from the filter field focuses the last tab * - ArrowUp from the filter field focuses the last tab
* - Home/PageUp focuses the filter field * - Home/PageUp focuses the filter field
* - End/PageDown focues the last tab title * - End/PageDown focues the last tab title
* - CMD-f will focus the input field
*/ */
this.handleTabsMenuKeyPress = function (event) { this.handleTabsMenuKeyPress = function (event) {
let tabindex = this._tabsMenuFocusedIndex; let tabindex = this._tabsMenuFocusedIndex;
@ -1114,5 +1119,14 @@ var Zotero_Tabs = new function () {
} }
event.target.click(); event.target.click();
} }
else if (["ArrowLeft", "ArrowRight"].includes(event.key)) {
event.preventDefault();
event.stopPropagation();
}
else if (event.key == "f" && (Zotero.isMac ? event.metaKey : event.ctrlKey)) {
focusTabsMenuEntry(0);
event.preventDefault();
event.stopPropagation();
}
}; };
}; };

View file

@ -817,6 +817,7 @@
<vbox width="350" id="zotero-tabs-menu-wrapper"> <vbox width="350" id="zotero-tabs-menu-wrapper">
<html:input id="zotero-tabs-menu-filter" <html:input id="zotero-tabs-menu-filter"
oninput="Zotero_Tabs.handleTabsMenuFilterInput(event, this)" oninput="Zotero_Tabs.handleTabsMenuFilterInput(event, this)"
onfocus="Zotero_Tabs.resetFocusIndex()"
tabindex="0" tabindex="0"
data-l10n-id="zotero-tabs-menu-filter" data-l10n-id="zotero-tabs-menu-filter"
/> />