Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -5185,9 +5185,9 @@ function makeTab(tabNb, text, results, query, isTypeSearch, goToFirst) {
errorReport.className = "error";
errorReport.innerHTML = `Query parser error: "${error.join("")}".`;
search.insertBefore(errorReport, search.firstElementChild);
} else if (goToFirst ||
} else if (tabNb === 0 && (goToFirst ||
(count === 1 && getSettingValue("go-to-only-result") === "true")
) {
)) {
// Needed to force re-execution of JS when coming back to a page. Let's take this
// scenario as example:
//
Expand Down
46 changes: 44 additions & 2 deletions tests/rustdoc-gui/setting-go-to-only-result.goml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ assert-local-storage: {"rustdoc-go-to-only-result": "true"}

go-to: "file://" + |DOC_PATH| + "/lib2/index.html"
// We enter it into the search.
click: "#search-button"
wait-for: "#alternative-display .search-input"

@GuillaumeGomez GuillaumeGomez Jun 23, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised it worked before to directly write into the search input even if it's not displayed. It triggered a bug when I wrote Whitespace into it: it only had pace, the beginning was removed. I think it's because the item gets moved in-between and if there are few enough letters, it works, but it's only by change.

View changes since the review

write-into: (".search-input", "HasALongTraitWithParams")
wait-for-document-property: {"title": "HasALongTraitWithParams in lib2 - Rust"}
assert-window-property: ({"location": "/lib2/struct.HasALongTraitWithParams.html"}, ENDS_WITH)
assert-window-property: ({"location"."pathname": "/lib2/struct.HasALongTraitWithParams.html"}, ENDS_WITH)

@GuillaumeGomez GuillaumeGomez Jun 23, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no clue how this could have work before since window.location is indeed an object. Gonna investigate on browser-ui-test side.

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// Regression test for <https://github.com/rust-lang/rust/issues/112676>.
// If "go-to-only-result" is enabled and you go back to history, it should not lead you back to the
// page result again automatically.
history-go-back:
wait-for-document-property: {"title": "lib2 - Rust"}
assert-window-property: ({"location": "/lib2/index.html"}, ENDS_WITH)
assert-window-property: ({"location"."pathname": "/lib2/index.html"}, ENDS_WITH)

// We try again to see if it goes to the only result
go-to: "file://" + |DOC_PATH| + "/lib2/index.html?search=HasALongTraitWithParams"
Expand All @@ -69,3 +71,43 @@ call-function: ("check-setting", {
"storage_value": "false",
"setting_attribute_value": "false",
})

define-function: (
"search-multiple-results",
[location],
block {
// We wait for the search to be done.
wait-for: ".search-form"
// We ensure the page didn't change.
assert-window-property: {"location"."pathname": |location|}
// We ensure that there is more than 0 results.
wait-for-text: ("#search-tabs > button:nth-child(1) .count", "(2)", CONTAINS)
wait-for-text: ("#search-tabs > button:nth-child(2) .count", "(1)", CONTAINS)
wait-for-text: ("#search-tabs > button:nth-child(3) .count", "(0)", CONTAINS)
},
)

// This is a regression test to ensure that it works when the setting is switched in-between. It
// could be reproduced by:
// 1. Doing a search (with "in parameters" or "in return types" having exactly one result)
// 2. Enabling the setting to true.
// 3. Reloading the page.

// First we go to a different page.
go-to: "file://" + |DOC_PATH| + "/lib2/index.html"

// The setting should be disabled.

@GuillaumeGomez GuillaumeGomez Jun 23, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To confirm this test works, run it without the fix. It should fail. :)

View changes since the review

assert-local-storage-false: {"rustdoc-go-to-only-result": "true"}
store-window-property: {"location"."pathname": location}
click: "#search-button"
wait-for: "#alternative-display .search-input"
write-into: (".search-input", "Whitespace")
call-function: ("search-multiple-results", {"location": |location|})

// We now toggle the setting and reload the page.
call-function: ("open-settings-menu", {})
click: "#go-to-only-result"
assert-local-storage: {"rustdoc-go-to-only-result": "true"}

reload:
call-function: ("search-multiple-results", {"location": |location|})
Loading