Tell me how to correctly place the cursor at the e...
# compose
v
Tell me how to correctly place the cursor at the end of the line when focusing
d
Maybe something like this is worth trying
Copy code
@Composable
fun Input(
    modifier: Modifier = Modifier,
    text: String
) {
    var textFieldValue by remember(text) {
        mutableStateOf(
            TextFieldValue(
                text = text,
                selection = TextRange(text.length, text.length)
            )
        )
    }

    BasicTextField(
        modifier = modifier.onFocusChanged { state ->
            if (state.isFocused) {
                val textLength = textFieldValue.text.length
                
                textFieldValue = textFieldValue.copy(
                    selection = TextRange(textLength, textLength)
                )
            }
        },
        value = textFieldValue,
        onValueChange = { value -> textFieldValue = value }
    )
}
🙏 1