Skip to content

Commit

Permalink
Add changing selection
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedRejeb committed Jul 25, 2023
1 parent 2280c87 commit 036c464
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/rich_text_state.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@ richTextState.setConfig(
codeBackgroundColor = Color.Transparent,
codeStrokeColor = Color.LightGray,
)
```

### Changing the editor's selection

The editor's selection can be changed using the `RichTextState.selection` property.

```kotlin
richTextState.selection = TextRange(0, 5)
```
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,18 @@ class RichTextState internal constructor(
var annotatedString by mutableStateOf(AnnotatedString(text = ""))
private set

val selection get() = textFieldValue.selection
/**
* The selection of the rich text.
*/
var selection
get() = textFieldValue.selection
set(value) {
if (value.min >= 0 && value.max <= textFieldValue.text.length) {
val newTextFieldValue = textFieldValue.copy(selection = value)
updateTextFieldValue(newTextFieldValue)
}
}

val composition get() = textFieldValue.composition

internal var singleParagraphMode by mutableStateOf(false)
Expand Down

0 comments on commit 036c464

Please sign in to comment.