diff --git a/chrome/content/zotero/collectionTree.jsx b/chrome/content/zotero/collectionTree.jsx index df4cafff14..e9d517db76 100644 --- a/chrome/content/zotero/collectionTree.jsx +++ b/chrome/content/zotero/collectionTree.jsx @@ -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(); + } } diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 867c61af12..1e287f836c 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -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);