Skip to content

Commit ae61070

Browse files
authored
Rollup merge of #106069 - notriddle:notriddle/search-tabs, r=GuillaumeGomez
rustdoc: use a more evocative name for CSS/JS `#titles` This renames the ID, which is only used in search results, to `#search-tabs`. Also changes the `.count` to a span, so it doesn't need its display mode to be overridden.
2 parents d23cb73 + 7c6aa7c commit ae61070

11 files changed

+52
-52
lines changed

src/librustdoc/html/static/css/rustdoc.css

+4-5
Original file line numberDiff line numberDiff line change
@@ -1261,14 +1261,14 @@ a.test-arrow:hover {
12611261
margin-right: auto;
12621262
}
12631263

1264-
#titles {
1264+
#search-tabs {
12651265
display: flex;
12661266
flex-direction: row;
12671267
gap: 1px;
12681268
margin-bottom: 4px;
12691269
}
12701270

1271-
#titles > button {
1271+
#search-tabs button {
12721272
text-align: center;
12731273
font-size: 1.125rem;
12741274
border: 0;
@@ -1278,8 +1278,7 @@ a.test-arrow:hover {
12781278
color: inherit;
12791279
}
12801280

1281-
#titles > button > div.count {
1282-
display: inline-block;
1281+
#search-tabs .count {
12831282
font-size: 1rem;
12841283
color: var(--search-tab-title-count-color);
12851284
}
@@ -1706,7 +1705,7 @@ in storage.js
17061705
display: none !important;
17071706
}
17081707

1709-
#titles > button > div.count {
1708+
#search-tabs .count {
17101709
display: block;
17111710
}
17121711

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function printTab(nb) {
4949
let iter = 0;
5050
let foundCurrentTab = false;
5151
let foundCurrentResultSet = false;
52-
onEachLazy(document.getElementById("titles").childNodes, elem => {
52+
onEachLazy(document.getElementById("search-tabs").childNodes, elem => {
5353
if (nb === iter) {
5454
addClass(elem, "selected");
5555
foundCurrentTab = true;
@@ -1490,7 +1490,7 @@ function initSearch(rawSearchIndex) {
14901490
function focusSearchResult() {
14911491
const target = searchState.focusedByTab[searchState.currentTab] ||
14921492
document.querySelectorAll(".search-results.active a").item(0) ||
1493-
document.querySelectorAll("#titles > button").item(searchState.currentTab);
1493+
document.querySelectorAll("#search-tabs button").item(searchState.currentTab);
14941494
searchState.focusedByTab[searchState.currentTab] = null;
14951495
if (target) {
14961496
target.focus();
@@ -1645,9 +1645,9 @@ function initSearch(rawSearchIndex) {
16451645
function makeTabHeader(tabNb, text, nbElems) {
16461646
if (searchState.currentTab === tabNb) {
16471647
return "<button class=\"selected\">" + text +
1648-
" <div class=\"count\">(" + nbElems + ")</div></button>";
1648+
" <span class=\"count\">(" + nbElems + ")</span></button>";
16491649
}
1650-
return "<button>" + text + " <div class=\"count\">(" + nbElems + ")</div></button>";
1650+
return "<button>" + text + " <span class=\"count\">(" + nbElems + ")</span></button>";
16511651
}
16521652

16531653
/**
@@ -1712,12 +1712,12 @@ function initSearch(rawSearchIndex) {
17121712
let output = `<h1 class="search-results-title">Results${crates}</h1>`;
17131713
if (results.query.error !== null) {
17141714
output += `<h3>Query parser error: "${results.query.error}".</h3>`;
1715-
output += "<div id=\"titles\">" +
1715+
output += "<div id=\"search-tabs\">" +
17161716
makeTabHeader(0, "In Names", ret_others[1]) +
17171717
"</div>";
17181718
currentTab = 0;
17191719
} else if (results.query.foundElems <= 1 && results.query.returned.length === 0) {
1720-
output += "<div id=\"titles\">" +
1720+
output += "<div id=\"search-tabs\">" +
17211721
makeTabHeader(0, "In Names", ret_others[1]) +
17221722
makeTabHeader(1, "In Parameters", ret_in_args[1]) +
17231723
makeTabHeader(2, "In Return Types", ret_returned[1]) +
@@ -1727,7 +1727,7 @@ function initSearch(rawSearchIndex) {
17271727
results.query.elems.length === 0 ? "In Function Return Types" :
17281728
results.query.returned.length === 0 ? "In Function Parameters" :
17291729
"In Function Signatures";
1730-
output += "<div id=\"titles\">" +
1730+
output += "<div id=\"search-tabs\">" +
17311731
makeTabHeader(0, signatureTabTitle, ret_others[1]) +
17321732
"</div>";
17331733
currentTab = 0;
@@ -1747,7 +1747,7 @@ function initSearch(rawSearchIndex) {
17471747
search.appendChild(resultsElem);
17481748
// Reset focused elements.
17491749
searchState.showResults(search);
1750-
const elems = document.getElementById("titles").childNodes;
1750+
const elems = document.getElementById("search-tabs").childNodes;
17511751
searchState.focusedByTab = [];
17521752
let i = 0;
17531753
for (const elem of elems) {

src/test/rustdoc-gui/basic-code.goml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
22
click: ".srclink"
3+
wait-for: ".src-line-numbers"
34
assert-count: (".src-line-numbers", 1)

src/test/rustdoc-gui/cursor.goml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ write: (".search-input", "Foo")
1212
// To be SURE that the search will be run.
1313
press-key: 'Enter'
1414
// Waiting for the search results to appear...
15-
wait-for: "#titles"
16-
assert-css: ("#titles > button", {"cursor": "pointer"})
15+
wait-for: "#search-tabs"
16+
assert-css: ("#search-tabs > button", {"cursor": "pointer"})
1717

1818
// mobile sidebar toggle button
1919
size: (500, 700)

src/test/rustdoc-gui/search-filter.goml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ write: (".search-input", "test")
55
// To be SURE that the search will be run.
66
press-key: 'Enter'
77
// Waiting for the search results to appear...
8-
wait-for: "#titles"
8+
wait-for: "#search-tabs"
99
assert-text: ("#results .externcrate", "test_docs")
1010

1111
wait-for: "#crate-search"
@@ -17,7 +17,7 @@ press-key: "ArrowDown"
1717
press-key: "ArrowDown"
1818
press-key: "Enter"
1919
// Waiting for the search results to appear...
20-
wait-for: "#titles"
20+
wait-for: "#search-tabs"
2121
assert-document-property: ({"URL": "&filter-crate="}, CONTAINS)
2222
// We check that there is no more "test_docs" appearing.
2323
assert-false: "#results .externcrate"
@@ -41,7 +41,7 @@ press-key: "ArrowUp"
4141
press-key: "ArrowUp"
4242
press-key: "Enter"
4343
// Waiting for the search results to appear...
44-
wait-for: "#titles"
44+
wait-for: "#search-tabs"
4545
assert-property: ("#crate-search", {"value": "all crates"})
4646

4747
// Checking that the URL parameter is taken into account for crate filtering.

src/test/rustdoc-gui/search-keyboard.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ write: (".search-input", "Foo")
55
// To be SURE that the search will be run.
66
press-key: 'Enter'
77
// Waiting for the search results to appear...
8-
wait-for: "#titles"
8+
wait-for: "#search-tabs"
99

1010
// Now use the keyboard commands to switch to the third result.
1111
press-key: "ArrowDown"

src/test/rustdoc-gui/search-result-color.goml

+7-7
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ local-storage: {
6565
reload:
6666

6767
// Waiting for the search results to appear...
68-
wait-for: "#titles"
68+
wait-for: "#search-tabs"
6969
assert-css: (
70-
"#titles > button > div.count",
70+
"#search-tabs > button > .count",
7171
{"color": "rgb(136, 136, 136)"},
7272
ALL,
7373
)
@@ -182,9 +182,9 @@ local-storage: {
182182
reload:
183183

184184
// Waiting for the search results to appear...
185-
wait-for: "#titles"
185+
wait-for: "#search-tabs"
186186
assert-css: (
187-
"#titles > button > div.count",
187+
"#search-tabs > button > .count",
188188
{"color": "rgb(136, 136, 136)"},
189189
ALL,
190190
)
@@ -284,9 +284,9 @@ local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"}
284284
reload:
285285

286286
// Waiting for the search results to appear...
287-
wait-for: "#titles"
287+
wait-for: "#search-tabs"
288288
assert-css: (
289-
"#titles > button > div.count",
289+
"#search-tabs > button > .count",
290290
{"color": "rgb(136, 136, 136)"},
291291
ALL,
292292
)
@@ -396,7 +396,7 @@ define-function: (
396396
// To be SURE that the search will be run.
397397
("press-key", 'Enter'),
398398
// Waiting for the search results to appear...
399-
("wait-for", "#titles"),
399+
("wait-for", "#search-tabs"),
400400
// Checking that the colors for the alias element are the ones expected.
401401
("assert-css", (".result-name > .alias", {"color": |alias|})),
402402
("assert-css", (".result-name > .alias > .grey", {"color": |grey|})),
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// This test is to ensure that the codeblocks are correctly rendered in the search results.
22
goto: "file://" + |DOC_PATH| + "/test_docs/index.html?search=some_more_function"
33
// Waiting for the search results to appear...
4-
wait-for: "#titles"
4+
wait-for: "#search-tabs"
55
assert-text: (".search-results .desc code", "format!")

src/test/rustdoc-gui/search-result-go-to-first.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ assert-text-false: (".fqn", "Struct test_docs::Foo")
88
// We now check that we land on the search result page if "go_to_first" isn't set.
99
goto: "file://" + |DOC_PATH| + "/test_docs/index.html?search=struct%3AFoo"
1010
// Waiting for the search results to appear...
11-
wait-for: "#titles"
11+
wait-for: "#search-tabs"
1212
assert-text-false: (".fqn", "Struct test_docs::Foo")
1313
// Ensure that the search results are displayed, not the "normal" content.
1414
assert-css: ("#main-content", {"display": "none"})

src/test/rustdoc-gui/search-result-keyword.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ write: (".search-input", "CookieMonster")
44
// To be SURE that the search will be run.
55
press-key: 'Enter'
66
// Waiting for the search results to appear...
7-
wait-for: "#titles"
7+
wait-for: "#search-tabs"
88
// Note: The two next assert commands could be merged as one but readability would be
99
// less good.
1010
//

src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml

+23-23
Original file line numberDiff line numberDiff line change
@@ -5,70 +5,70 @@ write: (".search-input", "Foo")
55
// To be SURE that the search will be run.
66
press-key: 'Enter'
77
// Waiting for the search results to appear...
8-
wait-for: "#titles"
9-
assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"})
10-
assert-text: ("#titles > button:nth-of-type(1)", "In Names", STARTS_WITH)
8+
wait-for: "#search-tabs"
9+
assert-attribute: ("#search-tabs > button:nth-of-type(1)", {"class": "selected"})
10+
assert-text: ("#search-tabs > button:nth-of-type(1)", "In Names", STARTS_WITH)
1111
assert: "input.search-input:focus"
1212
// Use left-right keys
1313
press-key: "ArrowDown"
1414
assert: "#results > .search-results.active > a:nth-of-type(1):focus"
1515
press-key: "ArrowRight"
16-
wait-for-attribute: ("#titles > button:nth-of-type(2)", {"class": "selected"})
16+
wait-for-attribute: ("#search-tabs > button:nth-of-type(2)", {"class": "selected"})
1717
press-key: "ArrowRight"
18-
wait-for-attribute: ("#titles > button:nth-of-type(3)", {"class": "selected"})
18+
wait-for-attribute: ("#search-tabs > button:nth-of-type(3)", {"class": "selected"})
1919
press-key: "ArrowRight"
20-
wait-for-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"})
20+
wait-for-attribute: ("#search-tabs > button:nth-of-type(1)", {"class": "selected"})
2121
press-key: "ArrowLeft"
22-
wait-for-attribute: ("#titles > button:nth-of-type(3)", {"class": "selected"})
22+
wait-for-attribute: ("#search-tabs > button:nth-of-type(3)", {"class": "selected"})
2323

2424
// Now try search-by-return
2525
goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
2626
write: (".search-input", "-> String")
2727
// To be SURE that the search will be run.
2828
press-key: 'Enter'
2929
// Waiting for the search results to appear...
30-
wait-for: "#titles"
31-
assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"})
32-
assert-text: ("#titles > button:nth-of-type(1)", "In Function Return Types", STARTS_WITH)
30+
wait-for: "#search-tabs"
31+
assert-attribute: ("#search-tabs > button:nth-of-type(1)", {"class": "selected"})
32+
assert-text: ("#search-tabs > button:nth-of-type(1)", "In Function Return Types", STARTS_WITH)
3333
assert: "input.search-input:focus"
3434
// Use left-right keys
3535
press-key: "ArrowDown"
3636
assert: "#results > .search-results.active > a:nth-of-type(1):focus"
3737
press-key: "ArrowRight"
38-
wait-for-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"})
38+
wait-for-attribute: ("#search-tabs > button:nth-of-type(1)", {"class": "selected"})
3939
press-key: "ArrowRight"
40-
wait-for-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"})
40+
wait-for-attribute: ("#search-tabs > button:nth-of-type(1)", {"class": "selected"})
4141
press-key: "ArrowRight"
42-
wait-for-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"})
42+
wait-for-attribute: ("#search-tabs > button:nth-of-type(1)", {"class": "selected"})
4343
press-key: "ArrowLeft"
44-
wait-for-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"})
44+
wait-for-attribute: ("#search-tabs > button:nth-of-type(1)", {"class": "selected"})
4545

4646
// Try with a search-by-return with no results
4747
goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
4848
write: (".search-input", "-> Something")
4949
// To be SURE that the search will be run.
5050
press-key: 'Enter'
5151
// Waiting for the search results to appear...
52-
wait-for: "#titles"
53-
assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"})
54-
assert-text: ("#titles > button:nth-of-type(1)", "In Function Return Types", STARTS_WITH)
52+
wait-for: "#search-tabs"
53+
assert-attribute: ("#search-tabs > button:nth-of-type(1)", {"class": "selected"})
54+
assert-text: ("#search-tabs > button:nth-of-type(1)", "In Function Return Types", STARTS_WITH)
5555

5656
// Try with a search-by-parameter
5757
goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
5858
write: (".search-input", "usize pattern")
5959
// To be SURE that the search will be run.
6060
press-key: 'Enter'
6161
// Waiting for the search results to appear...
62-
wait-for: "#titles"
63-
assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"})
64-
assert-text: ("#titles > button:nth-of-type(1)", "In Function Parameters", STARTS_WITH)
62+
wait-for: "#search-tabs"
63+
assert-attribute: ("#search-tabs > button:nth-of-type(1)", {"class": "selected"})
64+
assert-text: ("#search-tabs > button:nth-of-type(1)", "In Function Parameters", STARTS_WITH)
6565

6666
// Try with a search-by-parameter-and-return
6767
goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
6868
write: (".search-input", "pattern -> str")
6969
// To be SURE that the search will be run.
7070
press-key: 'Enter'
7171
// Waiting for the search results to appear...
72-
wait-for: "#titles"
73-
assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"})
74-
assert-text: ("#titles > button:nth-of-type(1)", "In Function Signatures", STARTS_WITH)
72+
wait-for: "#search-tabs"
73+
assert-attribute: ("#search-tabs > button:nth-of-type(1)", {"class": "selected"})
74+
assert-text: ("#search-tabs > button:nth-of-type(1)", "In Function Signatures", STARTS_WITH)

0 commit comments

Comments
 (0)