Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextInput: Include the caretIndex property #178

Closed
wants to merge 1 commit into from

Conversation

dimensionscape
Copy link
Contributor

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.

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.
@joshtynjala
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants