For a regular EditText, we can get the cursor position by calling the getSelectionStart() method
That is because EditText
is stateful.
In Jetpack Compose this posibility is available for ClickableText, but apparently not for TextField or OutlinedTextField.
Composables are stateless.
Has anyone come across this problem and know how to solve it?
In the case of BasicTextField()
and related composables, use the composable where your state is TextFieldValue
. Then, the selection
property of the TextFieldValue
has a TextRange
that you can use to get the cursor position.
TextFieldValue
. Please, check if this answer helps you #68244862 – Ralph