TextFieldState

@Stable
class TextFieldState(initialText: String = "")

The editable text of a TextField, the position of its cursor, and its selection.

The cursor is an index into text between two characters, where 0 is before the first one and the length of text is after the last one. The selection reaches from where it started, its anchor, to the cursor. Without a selection, the anchor is at the cursor.

Edits are recorded so that undo and redo can step through them, with typed characters grouped by word.

Constructors

Link copied to clipboard
constructor(initialText: String = "")

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
var cursor: Int

Setting the cursor moves it to the closest character boundary within the text, and removes the selection.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The end of the selection. Without a selection, the cursor.

Link copied to clipboard

The start of the selection, at most selectionEnd. Without a selection, the cursor.

Link copied to clipboard

Setting the text moves the cursor to its end, and is recorded like other edits.

Functions

Link copied to clipboard
fun clear()
Link copied to clipboard
fun insert(text: String)

Replaces the selection by text, or inserts it at the cursor, and moves the cursor after it.

Link copied to clipboard
fun redo(): Boolean

Repeats the last edit which was undone, and returns false when there is none.

Link copied to clipboard
fun select(anchor: Int, cursor: Int)

Selects from anchor to cursor, where the cursor is placed.

Link copied to clipboard
fun selectAll()
Link copied to clipboard
fun undo(): Boolean

Reverts the last edit, and returns false when there is none.