Haha! This was a little unexpected from a `BasicTe...
# compose-desktop
v
Haha! This was a little unexpected from a `BasicTextField`function!
j
Yes, that does seem unexpected, please do file a bug.
v
The error was in my code. I had written this:
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:
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
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.
So that is working as expected
When you create a TextFieldValue, you are fully controlling the behavior of the text field.
r
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
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.
👍 3