feathersui-openfl
feathersui-openfl copied to clipboard
TextInput: Include the caretIndex property
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.
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.