Skip to content

Commit

Permalink
Rollup merge of rust-lang#72967 - integer32llc:prevent-default-arrows…
Browse files Browse the repository at this point in the history
…, r=kinnison

Don't move cursor in search box when using arrows to navigate results

## What happens

- Go to https://doc.rust-lang.org/stable/std/index.html
- Press 's' to focus the search box
- Type a query like 'test'
- Press the down arrow one or more times to change which search result is highlighted
- Press the up arrow once to go up one search result
- Notice the cursor in the search box is now at the beginning of your query, such that if you now typed 'a' the search box would contain 'atest', when it would be expected that the cursor would have remained where it was and if you typed 'a' at this point it would result in 'testa'
- Press the down arrow once to go down one search result
- Now notice the cursor is at the end of your query again

## What I expected

I expected that changing which search result was highlighted using the up and down arrows would have no effect on where the cursor was in the search box.

## The fix

This PR prevents the default action of the up and down arrows when the custom keydown events are happening during a search.
  • Loading branch information
Manishearth authored Jun 26, 2020
2 parents 887ce8e + e85df08 commit c6683a5
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,7 @@ function defocusSearchBar() {

addClass(actives[currentTab][0].previousElementSibling, "highlighted");
removeClass(actives[currentTab][0], "highlighted");
e.preventDefault();
} else if (e.which === 40) { // down
if (!actives[currentTab].length) {
var results = document.getElementById("results").childNodes;
Expand All @@ -1421,6 +1422,7 @@ function defocusSearchBar() {
addClass(actives[currentTab][0].nextElementSibling, "highlighted");
removeClass(actives[currentTab][0], "highlighted");
}
e.preventDefault();
} else if (e.which === 13) { // return
if (actives[currentTab].length) {
document.location.href =
Expand Down

0 comments on commit c6683a5

Please sign in to comment.