-
-
Notifications
You must be signed in to change notification settings - Fork 139
Open
Description
Hi! Thanks for your work.
Is there a way to modify the style of selected text ?
It might be useful to provide a method called setAnnotatedString.
For example, Ctrl + B makes the selected text bold :
val richTextState = rememberRichTextState()
BasicRichTextEditor(
state = richTextState,
modifier = Modifier.fillMaxSize().padding(horizontal = 16.dp, vertical = 8.dp).onKeyEvent {
if (it.isCtrlPressed && it.key == Key.B) {
val annotatedString = richTextState.annotatedString
val selection = richTextState.selection
val startIndex = selection.min
val endIndex = selection.max
val selectedText = annotatedString.substring(startIndex, endIndex)
val newAnnotatedString = buildAnnotatedString {
append(annotatedString.subSequence(startIndex = 0, endIndex = startIndex))
append(
buildAnnotatedString {
append(selectedText)
addStyle(SpanStyle(fontWeight = FontWeight.Bold), 0, selectedText.length)
}
)
append(annotatedString.subSequence(startIndex = endIndex, endIndex = annotatedString.length))
}
// richTextState.setAnnotatedString(newAnnotatedString)
true
} else {
false
}
},
)Metadata
Metadata
Assignees
Labels
No labels