Skip to content

Commit 5e753ca

Browse files
authored
Rollup merge of #104415 - notriddle:notriddle/search-keyboard-commands, r=GuillaumeGomez
rustdoc: fix corner case in search keyboard commands This fixes a bug when that shows up in nightly and in stable where: * Search something * Press down: first result is highlighted * Press down: second result is highlighted * Press down: third result is highlighted * Press right: first result of second tab is highlighted * Press left: third result of first tab is highlighted * Press up: second result is highlighted * Press up: first result is highlighted * Press up: Search box is highlighted * Press down: **third result** is highlighted, where it ought to highlight the first result
2 parents f17828d + 7b00534 commit 5e753ca

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,7 @@ function initSearch(rawSearchIndex) {
14911491
const target = searchState.focusedByTab[searchState.currentTab] ||
14921492
document.querySelectorAll(".search-results.active a").item(0) ||
14931493
document.querySelectorAll("#titles > button").item(searchState.currentTab);
1494+
searchState.focusedByTab[searchState.currentTab] = null;
14941495
if (target) {
14951496
target.focus();
14961497
}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Checks that the search tab results work correctly with function signature syntax
2+
// First, try a search-by-name
3+
goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
4+
write: (".search-input", "Foo")
5+
// To be SURE that the search will be run.
6+
press-key: 'Enter'
7+
// Waiting for the search results to appear...
8+
wait-for: "#titles"
9+
10+
// Now use the keyboard commands to switch to the third result.
11+
press-key: "ArrowDown"
12+
press-key: "ArrowDown"
13+
press-key: "ArrowDown"
14+
assert: ".search-results.active > a:focus:nth-of-type(3)"
15+
16+
// Now switch to the second tab, then back to the first one, then arrow back up.
17+
press-key: "ArrowRight"
18+
assert: ".search-results.active:nth-of-type(2) > a:focus:nth-of-type(1)"
19+
press-key: "ArrowLeft"
20+
assert: ".search-results.active:nth-of-type(1) > a:focus:nth-of-type(3)"
21+
press-key: "ArrowUp"
22+
assert: ".search-results.active > a:focus:nth-of-type(2)"
23+
press-key: "ArrowUp"
24+
assert: ".search-results.active > a:focus:nth-of-type(1)"
25+
press-key: "ArrowUp"
26+
assert: ".search-input:focus"
27+
press-key: "ArrowDown"
28+
assert: ".search-results.active > a:focus:nth-of-type(1)"

0 commit comments

Comments
 (0)