I want to select all the characters in the text field when the text field is shown on the screen. When passing the same index like TextRange(2,2) it works fine but when using a different index like TextRange(0, name.length)), the selection is not working. I have mentioned the function below
@Composable
fun TestFunction(name: String) {
var fieldValue by remember {
mutableStateOf(TextFieldValue(name, selection = TextRange(0, name.length)))
}
val focusRequester by remember {
mutableStateOf(FocusRequester())
}
DisposableEffect(Unit) {
focusRequester.requestFocus()
onDispose { }
}
BasicTextField(
value = fieldValue,
onValueChange = { fieldValue = it },
modifier = Modifier.focusRequester(focusRequester),
)
}
(2,2)place pointer after second character and(0, name.length)highlights whole text and it gets deleted by backspace. Try removing character, maybe selection missing color in your case? Selection handles with "copy/paste/etc" not visible like if I would open it by hard, maybe that's what are you talking about? Add string with which it doesn't work for you, it may be related.