Rollup merge of #109633 - GuillaumeGomez:fix-go-to-only-setting, r=notriddle

Fix "Directly go to item in search if there is only one result" setting

Part of #66181.

The setting was actually broken, so I fixed it when I added the GUI test.

r? `@notriddle`
This commit is contained in:
Matthias Krüger 2023-03-27 08:46:53 +02:00 committed by GitHub
commit b39db705f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 5 deletions

View file

@ -1946,11 +1946,7 @@ function initSearch(rawSearchIndex) {
function showResults(results, go_to_first, filterCrates) {
const search = searchState.outputElement();
if (go_to_first || (results.others.length === 1
&& getSettingValue("go-to-only-result") === "true"
// By default, the search DOM element is "empty" (meaning it has no children not
// text content). Once a search has been run, it won't be empty, even if you press
// ESC or empty the search input (which also "cancels" the search).
&& (!search.firstChild || search.firstChild.innerText !== searchState.loadingText))
&& getSettingValue("go-to-only-result") === "true")
) {
const elem = document.createElement("a");
elem.href = results.others[0].href;