slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
16.91k stars 562 forks source link

One-line text box widgets should select all text when receiving focus via keyboard #5992

Open Enyium opened 2 weeks ago

Enyium commented 2 weeks ago

Widgets like LineEdit and SpinBox should select all of their text when they receive focus via keyboard. At least on Windows, this is common behavior.

In a shortcut (.lnk file) property dialog, e.g., you have multiple one-line text boxes. Initially, they are horizontally scrolled (no scrollbar, of course), so that the start of the text aligns with the left side of the text box. When you focus it, all text is selected, and (if it contains more text than can be displayed) the text box is horizontally scrolled, so that the end of the text aligns with the right side of the text box. When you then focus away from the text box, the horizontal scroll position stays the one that focusing established.

I wouldn't currently rule out that you could come up with a behavior regarding horizontal scrolling on focusing and unfocusing that'd be more desirable (probably taking into account, whether it was horizontally navigated between focusing and unfocusing). But the selection part helps with quick overwriting and is very useful in my opinion.

In the browser, I tested the text boxes on the following webpages as also implementing this behavior:

FloVanGH commented 2 days ago

Hi and thank you for your report.

@ogoffart this is more a a:text topic right?

tronical commented 2 days ago

Hmm, is it though? The functionality is there (it's possible to call select-all()), but whether this is to be done or not depends on the style?

ogoffart commented 2 days ago

A Qt application on linux does it, as well as firefox. Reporter says it is like that on Windows. I think it still make sense to implement that in TextInput rather than on the style and having it gated it with #[cfg(not(target_vendor = "apple"))].

tronical commented 14 hours ago

You're right :)