slint
slint copied to clipboard
Add `selected` callback for TextInput
ChangeLog: Added selected callback for TextInput
Closes #6450
Thanks for the patch!
This only call the callback if the selection is made with the mouse, and only when releasing the mouse. I think it should also be called when the selection is done with the keyboard, not?
The new callback should be documented in docs/reference/src/language/builtins/elements.md
A test would be nice. For example, tests/cases/text/select_double_click.slint could be extended with checking that the callback was called. There are other test in that folder that can be used as inspiration.
This only call the callback if the selection is made with the mouse, and only when releasing the mouse. I think it should also be called when the selection is done with the keyboard, not?
You are right. I'll add these changes.
I met some code in tests, which made me think we can make this callback inside slint file with properties and callbacks we have now:
property <bool> text_selected: self.anchor-position-byte-offset != self.cursor-position-byte-offset;
cursor-position-changed(new_pos) => {
if text_selected {
...
}
}
And I'm not sure about callback naming anymore. It's more selecting_canceled or something like this if we invoke it only when mouse key released.
And by keyboard it looks like it should be invoked only when shift key releases, but now it's only possible to invoke it per any keyboard move event or "select all" shortcut and I'm not sure it matches with mouse's behavior.
@ogoffart do you really think this callback need if we already can implement it by this code?
property <bool> text_selected: self.anchor-position-byte-offset != self.cursor-position-byte-offset;
cursor-position-changed(new_pos) => {
if text_selected {
...
}
}