slint icon indicating copy to clipboard operation
slint copied to clipboard

Add `selected` callback for TextInput

Open lmaxyz opened this issue 1 year ago • 5 comments

ChangeLog: Added selected callback for TextInput

Closes #6450

lmaxyz avatar Oct 07 '24 23:10 lmaxyz

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Oct 07 '24 23:10 CLAassistant

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.

ogoffart avatar Oct 08 '24 07:10 ogoffart

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.

lmaxyz avatar Oct 08 '24 17:10 lmaxyz

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.

lmaxyz avatar Oct 09 '24 00:10 lmaxyz

@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 {
        ...
    }
}

lmaxyz avatar Oct 14 '24 15:10 lmaxyz