rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.24k stars 12.45k forks source link

Feature Request: Focusing search results when directly navigating to rustdoc search #86882

Open insou22 opened 3 years ago

insou22 commented 3 years ago

When users type something like !rust Box into a search engine like DuckDuckGo, it will navigate you to the docs.rs std search like this: https://doc.rust-lang.org/std/?search=Box

The behavior I would like to see is that once I reach the search page, I can simply hit Enter to navigate to the first result: std::boxed::Box, or alternatively navigate between the different options just by immediately using the arrow keys -- i.e. not having to use the mouse. The current behavior is that I have to either click on the option I want with my mouse, or click into the search bar before I'm able to then use the arrow keys / Enter to get to my option.

Is it a possibility to make it so that when a search query page is directly navigated to, it can allow you to immediately interact with the search results via keyboard? Obviously we wouldn't want to steal input focus away from a user who is still typing their query in however, so that's an important distinction.

I'm also happy to have a go at implementing this feature myself, assuming this is something that people are happy to see integrated.

Cheers!

Nemo157 commented 3 years ago

The search page is actually part of rustdoc, docs.rs just hosts it for non-std crates, so I've transferred the issue over.

insou22 commented 3 years ago

Oh I didn't realise -- thanks for that!

GuillaumeGomez commented 3 years ago

The focus on the search input was ruled out in https://github.com/rust-lang/rust/pull/77333 because it prevented to scroll the page with the spacebar. However, in what you suggested, it wouldn't prevent it. I think we should go for it.

What do you think @rust-lang/rustdoc ?

Manishearth commented 3 years ago

Yeah if it's directly navigated to it makes sense

Though actually what I want is a query parameter that will also navigate directly to the first result on your behalf so that I can set up my custom searches to use it.

GuillaumeGomez commented 3 years ago

@Manishearth You mean like this: https://github.com/rust-lang/rust/pull/85876 ? ;)

Manishearth commented 3 years ago

Oh we landed that cool!

insou22 commented 3 years ago

Thanks for linking the related issues / PRs @GuillaumeGomez !

I'm wondering if this solution breaks that premise also, as although you can still use the spacebar to scroll the page, up/down won't scroll anymore.

Is this a reasonable compromise for both sides of things, or still just the same issue?

GuillaumeGomez commented 3 years ago

Up/down would still work actually. We made a lot of changes recently on the search results, so now the event isn't only when you are focused on the search input but also when you are focused on a search result "row". So in this regard, it would be perfectly fine.

insou22 commented 3 years ago

Ah okay, so please correct me if I'm wrong here but as I understand it, we would only be making navigate to the first result, and up/down will still simply scroll the page rather than navigating through the search results?

GuillaumeGomez commented 3 years ago

No, if a search result is focused, up/down would go through the search results, not scroll the page. However, the spacebar would scroll.