feathersui-openfl icon indicating copy to clipboard operation
feathersui-openfl copied to clipboard

TextInput: Include the caretIndex property

Open dimensionscape opened this issue 1 year ago • 1 comments

Here is a proposal for caret index. It would be nice to have access to it in many cases. I assume it is just an oversight not to include it already. Allowing to set the caret is an optional bonus.

Example requirement:

If I want to create a TextInput for an integer with a restricted number of digits, but I want to allow negative values, I need to know the caret index to ensure users can not input a dash/minus sign at an arbitrary index when typing.

dimensionscape avatar Apr 28 '24 12:04 dimensionscape

The selection API in TextInput is actually modeled on StageText, which also doesn't have a caretIndex property. However, that's because selectionActiveIndex is always equal to caretIndex. So if you want the caretIndex, you want to look at selectionActiveIndex. If you need to know whether there is a selection of one or more characters, or if it is the caret only, compare whether selectionActiveIndex and selectionAnchorIndex are equal or not.

joshtynjala avatar Apr 29 '24 16:04 joshtynjala