From a2e034c9219fd36295425397f815c48aed286a6c Mon Sep 17 00:00:00 2001 From: abaevbog Date: Mon, 11 Dec 2023 04:35:26 -0500 Subject: [PATCH] collection search not focusing group on Enter fix While looking for the first matching row to select, stop looking and move focus to the tree only after the selection succeeded. Some matching rows, like groups header, are not selectable. If it's the first matching row, it will now be skipped. --- chrome/content/zotero/collectionTree.jsx | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/chrome/content/zotero/collectionTree.jsx b/chrome/content/zotero/collectionTree.jsx index f8f1225289..a0472c0f09 100644 --- a/chrome/content/zotero/collectionTree.jsx +++ b/chrome/content/zotero/collectionTree.jsx @@ -2446,18 +2446,27 @@ var CollectionTree = class CollectionTree extends LibraryTree { async focusFirstMatchingRow(scrollToLibrary) { let index = 0; let row = this.getRow(index); - while (index < this._rows.length && !this._matchesFilter(row.ref).matchesFilter) { + while (index < this._rows.length) { row = this.getRow(index); - if (!row.isOpen) { + if (this._matchesFilter(row.ref).matchesFilter) { + // The matching row may not be selectable (e.g. Group Libraries header). + // In that case, just keep looking for the next row + let wasSelected = await this.selectByID(row.id); + if (wasSelected) { + // If selection happened, move focus onto the tree + this.tree.focus(); + if (scrollToLibrary) { + this.ensureRowIsVisible(0); + } + return; + } + } + // Selection did not happen - keep going. Open any containers on the way + if (!this.isContainerOpen(index)) { await this.toggleOpenState(index); } index += 1; } - this.tree.focus(); - await this.selectByID(row.id); - if (scrollToLibrary) { - this.ensureRowIsVisible(0); - } } /**