BasicTextFieldUndoSample
@Sampled
@Composable
fun BasicTextFieldUndoSample() {
val state = rememberTextFieldState()
Column(Modifier.padding(8.dp)) {
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
Button(onClick = { state.undoState.undo() }, enabled = state.undoState.canUndo) {
Text("Undo")
}
Button(onClick = { state.undoState.redo() }, enabled = state.undoState.canRedo) {
Text("Redo")
}
Button(
onClick = { state.undoState.clearHistory() },
enabled = state.undoState.canUndo || state.undoState.canRedo,
) {
Text("Clear History")
}
}
BasicTextField(
state = state,
modifier =
Modifier.fillMaxWidth()
.border(1.dp, Color.LightGray, RoundedCornerShape(6.dp))
.padding(8.dp),
textStyle = TextStyle(fontSize = 16.sp),
)
}
}