John Oberhauser
07/29/2023, 1:51 AMval testText = remember { mutableStateOf(TextFieldValue()) }
TextField(
value = testText.value,
onValueChange = {
// should only happen when you type or move cursor
println("onValueChange called")
testText.value = it.copy(
annotatedString = buildAnnotatedString {
append(it.text)
},
)
},
)
However, some strange things happen when I add a style span:
val testText = remember { mutableStateOf(TextFieldValue()) }
TextField(
value = testText.value,
onValueChange = {
// should only happen when you type or move cursor
println("onValueChange called")
testText.value = it.copy(
annotatedString = buildAnnotatedString {
withStyle(SpanStyle(Color.Blue)) {
append(it.text)
}
},
)
},
)
As I type, if my cursor is located in a word that begins with a letter, then the println is continuously called. But if my cursor is in a word that doesn't start with a letter, then the println acts normal. For example, if my text looks like @john{cursor here} is a person
or john 9{cursor here}9 test
then it's normal. But if my text looks like john{cursor here} is a person
then I get the continuous prints.
Any ideas?Jacob Ras
07/29/2023, 7:46 AMVisualTransformation
. The spans you add there are not interfered with by the IME.John Oberhauser
07/30/2023, 11:59 PMVisualTransformation
interface. I'm using that now and it works well. Thank you!