Haha! This was a little unexpected from a `BasicTextField`function!
j
jim
04/05/2021, 4:19 PM
Yes, that does seem unexpected, please do file a bug.
v
v79
04/05/2021, 4:44 PM
The error was in my code. I had written this:
v79
04/05/2021, 4:44 PM
Copy code
var sampleText = remember { mutableStateOf("The quick brown fox jumps over the lazy dog 0123456789. !\$£{}") }
BasicTextField(
value = TextFieldValue(text = sampleText.value),
onValueChange = { sampleText.value = it.text },
textStyle = TextStyle(fontFamily = font.toFontFamily(), fontSize = fontSize.sp)
)
instead of this:
v79
04/05/2021, 4:45 PM
Copy code
var sampleText by remember { mutableStateOf(TextFieldValue("The quick brown fox jumps over the lazy dog 0123456789. !\$£{}")) }
BasicTextField(
value = sampleText,
onValueChange = { newValue -> sampleText = newValue },
textStyle = TextStyle(fontFamily = font.toFontFamily(), fontSize = fontSize.sp)
)
j
jim
04/05/2021, 6:26 PM
Ah, well, that makes more sense. TextFieldValue includes the cursor position. If you create a new instance and don't set the cursor position, it is going to have the default position, which is at the start of the text field.
jim
04/05/2021, 6:26 PM
So that is working as expected
jim
04/05/2021, 6:27 PM
When you create a TextFieldValue, you are fully controlling the behavior of the text field.
r
russhwolf
04/05/2021, 7:22 PM
I might have expected the default cursor position to be the end of the field instead of the beginning. That would help avoid this scenario which otherwise seems like a pretty easy trap to fall into.
j
jim
04/05/2021, 9:35 PM
Putting the cursor at the end might actually be worse, because it would hide the bug, and the bug would only appear when the user placed the cursor somewhere other than the end, and the developer might not have thought to test that and easily overlooked it.