Dave
03/17/2025, 4:08 PMStylianos Gakis
03/17/2025, 4:26 PMDave
03/17/2025, 7:17 PMDave
03/17/2025, 7:18 PMvar color = Color.Green
singleWindowApplication(
title = "Test",
) {
val regex = Regex("error")
val textState by remember { mutableStateOf(TextFieldState("this text contains error and other things.")) }
val outputTransformation = OutputTransformation({
val txt = this.originalText
if(txt.isNotEmpty()) {
val annotated = buildAnnotatedString {
regex.findAll(txt).forEach {
addStyle(SpanStyle(color), it.range.start, it.range.endInclusive+1)
}
}
setComposition(0, txt.length, annotated.annotations)
changeTracker.trackChange(0, txt.length, txt.length)
}
})
Surface {
Column {
Row {
Button(onClick = { color = Color.Red }) { Text("Red") }
Button(onClick = { color = Color.Blue }) { Text("Blue") }
}
BasicTextField(
cursorBrush = SolidColor(MaterialTheme.colorScheme.onSurface),
textStyle = TextStyle(color = MaterialTheme.colorScheme.onSurface),
state = textState,
modifier = Modifier
.fillMaxSize(),
outputTransformation = outputTransformation
)
}
}
}
Dave
03/17/2025, 7:19 PMStylianos Gakis
03/17/2025, 8:38 PM