Skip to content

Commit 7dfd0c2

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#66181. The setting was actually broken, so I fixed it when I added the GUI test. r? `@notriddle`
2 parents ac61f26 + bc9eec0 commit 7dfd0c2

File tree

2 files changed

+64
-5
lines changed

2 files changed

+64
-5
lines changed

src/librustdoc/html/static/js/search.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -1946,11 +1946,7 @@ function initSearch(rawSearchIndex) {
19461946
function showResults(results, go_to_first, filterCrates) {
19471947
const search = searchState.outputElement();
19481948
if (go_to_first || (results.others.length === 1
1949-
&& getSettingValue("go-to-only-result") === "true"
1950-
// By default, the search DOM element is "empty" (meaning it has no children not
1951-
// text content). Once a search has been run, it won't be empty, even if you press
1952-
// ESC or empty the search input (which also "cancels" the search).
1953-
&& (!search.firstChild || search.firstChild.innerText !== searchState.loadingText))
1949+
&& getSettingValue("go-to-only-result") === "true")
19541950
) {
19551951
const elem = document.createElement("a");
19561952
elem.href = results.others[0].href;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Checks that the setting "Directly go to item in search if there is only one result " is working as expected.
2+
3+
define-function: (
4+
"check-setting",
5+
(storage_value, setting_attribute_value),
6+
block {
7+
assert-local-storage: {"rustdoc-go-to-only-result": |storage_value|}
8+
click: "#settings-menu"
9+
wait-for: "#settings"
10+
assert-property: ("#go-to-only-result", {"checked": |setting_attribute_value|})
11+
}
12+
)
13+
14+
goto: "file://" + |DOC_PATH| + "/lib2/index.html"
15+
16+
call-function: ("check-setting", {
17+
"storage_value": null,
18+
"setting_attribute_value": "false",
19+
})
20+
21+
// By default, the search doesn't automatically go to the page if there is only one result.
22+
goto: "file://" + |DOC_PATH| + "/lib2/index.html?search=HasALongTraitWithParams"
23+
// It will timeout if the setting isn't working.
24+
wait-for: "#search"
25+
assert-document-property: ({"URL": "/lib2/index.html"}, CONTAINS)
26+
27+
// Now we change its value.
28+
click: "#settings-menu"
29+
wait-for: "#settings"
30+
click: "#go-to-only-result"
31+
assert-local-storage: {"rustdoc-go-to-only-result": "true"}
32+
33+
goto: "file://" + |DOC_PATH| + "/lib2/index.html"
34+
// We enter it into the search.
35+
write: (".search-input", "HasALongTraitWithParams")
36+
wait-for-document-property: {"title": "HasALongTraitWithParams in lib2 - Rust"}
37+
assert-document-property: ({"URL": "/lib2/struct.HasALongTraitWithParams.html"}, ENDS_WITH)
38+
39+
// We try again to see if it goes to the only result
40+
goto: "file://" + |DOC_PATH| + "/lib2/index.html?search=HasALongTraitWithParams"
41+
wait-for-document-property: {"title": "HasALongTraitWithParams in lib2 - Rust"}
42+
assert-document-property: ({"URL": "/lib2/struct.HasALongTraitWithParams.html"}, ENDS_WITH)
43+
44+
// We check the settings
45+
call-function: ("check-setting", {
46+
"storage_value": "true",
47+
"setting_attribute_value": "true",
48+
})
49+
50+
// And now we re-disable the setting.
51+
click: "#go-to-only-result"
52+
assert-local-storage: {"rustdoc-go-to-only-result": "false"}
53+
54+
goto: "file://" + |DOC_PATH| + "/lib2/index.html?search=HasALongTraitWithParams"
55+
// It will timeout if the setting isn't working.
56+
wait-for: "#search"
57+
assert-document-property: ({"URL": "/lib2/index.html"}, CONTAINS)
58+
59+
// And we check everything is back the way it was before.
60+
call-function: ("check-setting", {
61+
"storage_value": "false",
62+
"setting_attribute_value": "false",
63+
})

0 commit comments

Comments
 (0)