When focus returns to search box, auto highlight all text

If you perform a search and then click on the search icon or use the keyboard shortcut, the cursor will be placed at the end of the previous search term. To search for a new term, you must highlight the existing text via mousing, Crtl-A or Shift Arrows keys and then start typing.

The majority of the time I’m using searching, I’m attempting to search for something completely different than what I searched for earlier. If I want to refine, I enter the search results page and then refine the existing term from there.


In Google’s inbox, when focus is returned to search box, the entire existing term is auto highlighted:

That allows you to start typing immediately if you have a new term to search for, or hit the right arrow key if you need to refine an existing term. As a heavy searcher, I prefer the auto-highlight method and think Discourse should consider adopting it.

5 Likes

Sure this might be easy can you take a look next week @sam?

I implemented this while fixing some things with full page search.

https://github.com/discourse/discourse/pull/3757/commits

2 Likes

Careful I support autofocus if the search term is blank, if it is not blank focusing will lose search position in the page on back which is real bad

Could I clarify what “lose search position in the page” means? :sweat_smile:

I search for “testing”… scroll down 15 items, check one out, then hit back.

My expectation is that I return to the position I left, just like I do when using Google, not that I would be scrolled to the top with the word “testing” highlighted.

2 Likes

Ah ok. :+1: I’ll make the changes :smile:

I tested it out and the autofocus attribute doesn’t trigger on history back. However, it seems like the position on the page is preserved on Chrome but not on FireFox even without the autofocus attribute.

1 Like

Focus on safari touch will certainly cause scroll, would prefer to just avoid it for back navigation

2 Likes

Ic. In that case, I’ll just remove the autofocus :smile:

Focus should fire on first search load ONLY. Because on mobile you obviously want to type something in to search FOR, yes?

3 Likes

Remember to use ?mobile_view=1 to get mobile during testing.

1 Like

@wesochuck Patch has landed on master :smile: I really like the suggestion :+1:

1 Like

Lets close this :smile: :bear:

2 Likes

No… I do not support this… I just figured out what happens and it feels really weird.

If Google the mega search giant is not issuing a “select” on text in the box on focus… well there is a reason we should. I do not support “highlighting” all text on focus, that is just weird, if you want to do that it will have to be a plugin.

Google does not do this for Google.com
Ebay does not do this
Amazon does not do this
Microsoft does not do this
Apple do not do this, though they do this this strange thing

It’s a quirk of Google inbox, I don’t want us adopting this until it is prevalent, must be an extension.

2 Likes

Depends on how true “my next search is going to be totally different terms” is. Even on google, I often find myself selecting all then backspace to enter a new search term.

This behaviour is actually present in the address bar of browsers though one may argue that the probability of entering something new in the address bar is alot higher than a search input. :panda_face:

Yeah for browser address bars you have almost 100% confidence that its a brand new thing the user is going to type. So yeah it makes sense.

But as an end user I find it very surprising to see these magic auto select fields. I think facebook which seems to have set the trend gets away with it cause it displays so much when you click anyway:

I would argue that the behavior on Amazon and Google is different from what we have here. It doesn’t make sense for them to highlight the entire input because they are suggesting more terms based on the user’s input.

On Discourse, it sort of becomes a “trial and error” of keywords if I’m not exactly sure what I’m searching for. My search terms are often not an extension of the existing terms but totally new terms. :badpokerface: