From 741ed9b98c9cda3fa6f4c3177cf004458318cd73 Mon Sep 17 00:00:00 2001 From: abaevbog Date: Tue, 9 Jan 2024 02:03:03 -0500 Subject: [PATCH] minor collection search improvements - always scroll to selected row on empty filter - fixed a bug that would interfere with focusing on the selected collection on Enter if there are capital letters in the filter field --- chrome/content/zotero/collectionTree.jsx | 14 ++++++++++---- chrome/content/zotero/zoteroPane.js | 5 ++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/chrome/content/zotero/collectionTree.jsx b/chrome/content/zotero/collectionTree.jsx index a92e4eb84b..c2639226d8 100644 --- a/chrome/content/zotero/collectionTree.jsx +++ b/chrome/content/zotero/collectionTree.jsx @@ -2372,14 +2372,15 @@ var CollectionTree = class CollectionTree extends LibraryTree { * Set collection filter and refresh collectionTree to only include * rows that match the filter. Rows that do not match the filter but have children that do * are displayed as context rows. All relevant rows are toggled open. Selection is kept - * on the currently selected row if any. + * 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} scrollToSelected - Allow scrolling to the currently selected row. */ - async setFilter(filterText, scrollToSelected) { + async setFilter(filterText) { this._filter = filterText.toLowerCase(); let currentRow = this.getRow(this.selection.focused) || this._hiddenFocusedRow; let currentRowDisplayed = currentRow && this._includedInTree(currentRow.ref); + let scrollToSelected = filterText.length == 0; // If current row does not match any filters, it'll be hidden, so clear selection if (!currentRowDisplayed) { this.selection.clearSelection(); @@ -2410,6 +2411,11 @@ var CollectionTree = class CollectionTree extends LibraryTree { } } } + // If the selected collection is not scrolled to, scroll to the very top + if (!scrollToSelected) { + let collectionTable = document.getElementById("collection-tree").firstElementChild; + collectionTable.scrollTop = 0; + } } @@ -2439,7 +2445,7 @@ var CollectionTree = class CollectionTree extends LibraryTree { } filterEquals(filterValue) { - return filterValue === this._filter; + return filterValue.toLowerCase() === this._filter; } _isFilterEmpty() { diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index d0ded58bd2..018f3c4551 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -296,7 +296,7 @@ var ZoteroPane = new function() // Clear the search field if (collectionsSearchField.value.length) { collectionsSearchField.value = ''; - ZoteroPane.collectionsView.setFilter("", true); + ZoteroPane.collectionsView.setFilter(""); if (!removeFocus) { return null; } @@ -2747,8 +2747,7 @@ var ZoteroPane = new function() this.handleCollectionSearchInput = function () { let collectionsSearchField = document.getElementById("zotero-collections-search"); - // Set the filter without scrolling the selected row into the view - this.collectionsView.setFilter(collectionsSearchField.value, false); + this.collectionsView.setFilter(collectionsSearchField.value); }