interface TextFieldTextStyles
Provides access to the styles applied to the text within a TextFieldState.
This interface provides a style query API similar to TextFieldBuffer, but returns immutable data.
Use this interface when you only need to read the current text styles (e.g., to update a formatting toolbar UI). If you need to mutate the text styles, use TextFieldState.edit and the corresponding methods on TextFieldBuffer.
Do not use this interface to query styles within a TextFieldBuffer edit block. The data returned will not reflect any ongoing changes made to the buffer, as it only returns the unupdated state from before the edit block began.
Functions
getSpanStyles
fun getSpanStyles(start: Int, end: Int): List<AnnotatedString.Range<SpanStyle>>
Returns a list of AnnotatedString.Ranges representing the SpanStyles that intersect with the given range defined by start (inclusive) and end (exclusive).
Styles are returned in the same order they were originally added to the buffer.
A style intersects with the range if it overlaps with it at any point. For non-empty ranges, this means style.start < end and start < style.end.
Example Query Range: [5, 15)
0 5 10 15 20 25
|----|----|----|----|----| [---------) Query Range [5, 15)
[-------------------) Style [0, 20) (Contains query) -> Returned [----) Style [8, 12) (Inside query) -> Returned
[----------) Style [0, 10) (Overlap start) -> Returned
[----) Style [0, 5) (Touching start) -> NOT Returned [----------) Style [15, 25)(Touching end) -> NOT Returned
Example Collapsed Query: [10, 10)
0 5 10 15 20 25
|----|----|----|----|----| | Query Range [10, 10)
[-------------------) Style [0, 20) (Contains query) -> Returned
[---------) Style [0, 10) (Touching end) -> NOT Returned [----------) Style [10, 20)(Touching start) -> Returned
Parameters
| start | The start index of the range to query, inclusive. |
| end | The end index of the range to query, exclusive. |
Returns
| A list of AnnotatedString.Ranges representing the SpanStyles overlapping with the queried range. |
getParagraphStyles
fun getParagraphStyles(start: Int, end: Int): List<AnnotatedString.Range<ParagraphStyle>>
Returns a list of AnnotatedString.Ranges representing the ParagraphStyles that intersect with the given range defined by start (inclusive) and end (exclusive).
Styles are returned in the same order they were originally added to the buffer.
A style intersects with the range if it overlaps with it at any point. For non-empty ranges, this means style.start < end and start < style.end.
Example Query Range: [5, 15)
0 5 10 15 20 25
|----|----|----|----|----| [---------) Query Range [5, 15)
[-------------------) Style [0, 20) (Contains query) -> Returned [----) Style [8, 12) (Inside query) -> Returned
[----------) Style [0, 10) (Overlap start) -> Returned
[----) Style [0, 5) (Touching start) -> NOT Returned [----------) Style [15, 25)(Touching end) -> NOT Returned
Example Collapsed Query: [10, 10)
0 5 10 15 20 25
|----|----|----|----|----| | Query Range [10, 10)
[-------------------) Style [0, 20) (Contains query) -> Returned
[---------) Style [0, 10) (Touching end) -> NOT Returned [----------) Style [10, 20)(Touching start) -> Returned
Parameters
| start | The start index of the range to query, inclusive. |
| end | The end index of the range to query, exclusive. |
Returns
| A list of AnnotatedString.Ranges representing the ParagraphStyles overlapping with the queried range. |