Following the usual implementation, this is how we set the initial cursor to the end of text when setting the initial text:
var textState by remember { mutableStateOf(TextFieldValue("Hello", TextRange(4))) }
TextField(
value = textState,
onValueChange = { textState = it }
)
However, it doesn't seem to work and the cursor appears at the beginning of the text when I first focus on it. What's wrong here?
If I do nothing in onValueChange (just for testing purpose), then it works where the cursor shows at the end. Somehow onValueChange is messing it up.
TextField(
value = textState,
onValueChange = {}
)
Thanks
Your code seems fine to me.
There is an issue on the Google Issue Tracker that seems to go into the same direction, maybe it is related to your situation. A workaround proposed there is provided below, you can try if it works in your case:
If this does not resolve the problem, please create a new issue on the Issue Tracker.
If it resolved the problem, give the existing problem a +1 and leave a comment there with your code sample to help them reproduce it.