androidx.compose.foundation.text.selection

SelectionStateSince 1.12

Class · from org.jetbrains.compose.foundation:foundation:1.12.2

No hand-written docs yet.

Selection state object for a particular SelectionContainer. It is invalid for the same SelectionState to be passed to multiple SelectionContainers. Holds the currently selected text and functions to perform Selection actions programmatically.

class SelectionState

Used by

Parameters that take a SelectionState.

Properties

selectedTexts

val selectedTexts: List<AnnotatedString>

The currently selected texts in the SelectionContainer corresponding to this SelectionState, in visual/layout order. Each text composable within the Selection is returned as an AnnotatedString in the list. This field is backed by androidx.compose.runtime.mutableStateOf so it can be observed by Composables.

Saver

val Saver: Saver<SelectionState, Any>

Functions

selectAll

fun selectAll()

Sets the current selection to include every selectable Text Composable within the SelectionContainer.

clear

fun clear()

Clears the current selection for the SelectionContainer and removes selection handles.

extendSelectionByWord

fun extendSelectionByWord()

Extends the current selection to the next word boundary, if there is another word boundary available within the SelectionContainer. The next word is added at the active edge of the selection, following the current text direction. So if the selection is dragged in reverse, this adds a word earlier in the text.

getSelectableTexts

fun getSelectableTexts(): List<AnnotatedString>

Returns a list of all selectable texts within the SelectionContainer in visual/layout order. This returns the entire text content, including all selected or unselected portions. Text nodes excluded from selection using DisableSelection will not be included in the list. Calling this function can be inefficient for containers holding a large volume of text composables.

select

fun select(range: TextRange)

Sets the selection to the specified TextRange within the global space of all Texts inside the SelectionContainer. This function loops through all selectables in the SelectionContainer, so it is not advised to call within a loop or as an effect that triggers frequently.

Library docs

Selection state object for a particular SelectionContainer. It is invalid for the same SelectionState to be passed to multiple SelectionContainers. Holds the currently selected text and functions to perform Selection actions programmatically.

When instantiating this class from a composable, use rememberSelectionState to automatically save and restore the selection state. For more advanced use cases, pass SelectionState.Saver to rememberSaveable.