avoid blinking of focused collection row on escape

Make sure that on escape, the focus is moved to collectionTree strictly
once all filtered rows are rendered. Minor refactoring to achieve
it, since setFilter is async.
This commit is contained in:
Bogdan Abaev 2024-01-12 16:27:45 -05:00 committed by Dan Stillman
parent 0f0badea27
commit 2c97a7a03e
2 changed files with 15 additions and 12 deletions

View file

@ -2388,8 +2388,9 @@ var CollectionTree = class CollectionTree extends LibraryTree {
* on the currently selected row if any. If the filter is emptied out, the currently selected
* row is scrolled to. Otherwise, scroll to the very top.
* @param {String} filterText - Text that rows have to contain to match the filter
* @param {Bool} focusTree - Focus the collection tree after the filtering is complete
*/
async setFilter(filterText) {
async setFilter(filterText, focusTree = false) {
let collectionTable = document.getElementById("collection-tree").firstElementChild;
let isEmpty = this._isFilterEmpty();
let willBeEmpty = filterText.length == 0;
@ -2461,6 +2462,10 @@ var CollectionTree = class CollectionTree extends LibraryTree {
let scrollPosition = collectionTable.scrollTop + rowMiddle - tableMiddle;
collectionTable.scrollTop = scrollPosition;
}
// Focus the collection tree
if (focusTree) {
collectionTable.parentNode.focus();
}
}

View file

@ -292,18 +292,18 @@ var ZoteroPane = new function()
});
let collectionsSearchField = document.getElementById("zotero-collections-search");
let clearCollectionSearch = (removeFocus) => {
// Clear the search field
let clearCollectionSearch = () => {
// If empty filter - just focus the collectionTree
if (collectionsSearchField.value.length == 0) {
return document.getElementById("collection-tree");
}
// Clear the search field and focus collection tree
if (collectionsSearchField.value.length) {
collectionsSearchField.value = '';
ZoteroPane.collectionsView.setFilter("");
if (!removeFocus) {
return null;
}
ZoteroPane.collectionsView.setFilter("", true);
}
ZoteroPane.hideCollectionSearch();
// If the search field is empty, focus the collection tree
return document.getElementById('collection-tree');
return null;
};
collectionTreeToolbar.addEventListener("keydown", (event) => {
let actionsMap = {
@ -404,9 +404,7 @@ var ZoteroPane = new function()
// default to focusing on tag selector
return false;
},
Escape: () => {
clearCollectionSearch(true);
}
Escape: clearCollectionSearch
}
};
moveFocus(actionsMap, event);