slint-ui / slint

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

TextInput: add API to get and set the selection #3949

Open ogoffart opened 12 months ago

ogoffart commented 12 months ago

We should add an API in TextInput (and forward it in LineEdit and TextEdit) to get or set the selection positions

Discussed in https://github.com/slint-ui/slint/discussions/3899

tronical commented 10 months ago

What if we added a get-selected-text() function? That would be straightforward to implement and there’d be no expectation about re-evaluation of the selection changes z

ogoffart commented 10 months ago

if it have this:

VerticalLayout {
  foo := LineEdit {}
  Text { text: foo.get-selected-text(); }
} 

I'd expect the text to change when the selection is changed. (this is trivial to implement) API-wise, i'd probably name it just selected-text and i wonder if it shouldn't be a read-only property.

tronical commented 9 months ago

The setter part was implemented in #4164, but there's no getter yet.