# androidx.compose.foundation.text.input

Common/All

## Interfaces

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation` | A function that is ran after every change made to a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState` by user input and can change or reject that input. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/KeyboardActionHandler` |   | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/OutputTransformation` | A function (`https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/OutputTransformation#(androidx.compose.foundation.text.input.TextFieldBuffer).transformOutput()`) that transforms the text presented to a user by a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/BasicTextField.composable#BasicTextField(androidx.compose.foundation.text.input.TextFieldState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.text.input.InputTransformation,androidx.compose.ui.text.TextStyle,androidx.compose.foundation.text.KeyboardOptions,androidx.compose.foundation.text.input.KeyboardActionHandler,androidx.compose.foundation.text.input.TextFieldLineLimits,kotlin.Function2,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Brush,androidx.compose.foundation.text.input.OutputTransformation,androidx.compose.foundation.text.input.TextFieldDecorator,androidx.compose.foundation.ScrollState)`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer.ChangeList` | The ordered list of non-overlapping and discontinuous changes performed on a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer` during the current `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState#edit(kotlin.Function1)` or `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation#(androidx.compose.foundation.text.input.TextFieldBuffer).transformInput()` operation. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldDecorator` | Composable interface that allows to add decorations around text field, such as icon, placeholder, helper messages or similar, and automatically increase the hit target area of the text field. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldLineLimits` | Values that specify the text wrapping, scrolling, and height measurement behavior for text fields. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldTextStyles` | Provides access to the styles applied to the text within a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState`. | Cmn |

## Classes

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/ExpandPolicy` | Defines how a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TrackedRange` expands when text is inserted exactly at its boundaries. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer` | A text buffer that can be edited, similar to `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.text/-string-builder/index.html`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldLineLimits.MultiLine` | The text field will be at least `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldLineLimits.MultiLine#minHeightInLines()` tall, if the text overflows it will wrap, and if the text ends up being more than one line the field will grow until it is `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldLineLimits.MultiLine#maxHeightInLines()` tall and then start scrolling vertically. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState` | Manages editable text, selection, and cursor state for a text field. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextObfuscationMode` | Defines how the text will be obscured in secure text fields. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TrackedRange` | A style applied on the text that is tracked by `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer`, returned by `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer#addStyle(androidx.compose.ui.text.SpanStyle,kotlin.Int,kotlin.Int)`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/UndoState` | Controls the undo and redo history for a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState`. | Cmn |

## Objects

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation.Companion` |   | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldLineLimits.SingleLine` | The text field is always a single line tall, ignores newlines in the text, and scrolls horizontally when the text overflows. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState.Saver` | Saves and restores a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState` for `https://developer.android.com/reference/kotlin/androidx/compose/runtime/saveable/rememberSaveable.composable#rememberSaveable(kotlin.Array,androidx.compose.runtime.saveable.Saver,kotlin.String,kotlin.Function0)`. | Cmn |

## Composables

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/rememberTextFieldState.composable` | Create and remember a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState`. | Cmn |

## Extension functions summary

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation.https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).allCaps(androidx.compose.ui.text.intl.Locale)(locale: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/intl/Locale)` Returns a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation` that forces all text to be uppercase. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation.https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).byValue(kotlin.Function2)( transformation: (current: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html, proposed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html )` Creates an `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation` from a function that accepts both the current and proposed `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldCharSequence` and returns the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldCharSequence` to use for the field. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState.https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldState).clearText()()` Deletes all the text in the state. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer.https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer).delete(kotlin.Int,kotlin.Int)(start: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, end: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Delete the text between `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer).delete(kotlin.Int,kotlin.Int)` (inclusive) and `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer).delete(kotlin.Int,kotlin.Int)` (exclusive). | Cmn |
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer.ChangeList.https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer.ChangeList).forEachChange(kotlin.Function2)( block: (range: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange, originalRange: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Iterates over all changes in this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer.ChangeList` in order of their appearance in the text (from the lowest character offset to the highest). | Cmn |
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer.ChangeList.https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer.ChangeList).forEachChangeReversed(kotlin.Function2)( block: (range: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange, originalRange: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Iterates over all changes in this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer.ChangeList` in reverse order of their appearance in the text (from the highest character offset down to the lowest). | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer.https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer).insert(kotlin.Int,kotlin.String)(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, text: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Insert `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer).insert(kotlin.Int,kotlin.String)` at the given `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer).insert(kotlin.Int,kotlin.String)` in this value. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation.[maxLength](https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).maxLength(kotlin.Int))(maxLength: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` **This function is deprecated.** Use maxLengthTrim to truncate excess characters or maxLengthReject to reject input exceeding maxLength. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation.https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).maxLengthReject(kotlin.Int)(maxLength: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Rejects input changes that would cause the total length of the text field to exceed `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).maxLengthReject(kotlin.Int)` characters. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation.https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).maxLengthTrim(kotlin.Int)(maxLength: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Limits the total length of the text field to `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).maxLengthTrim(kotlin.Int)` characters by truncating inserted characters. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer.https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer).placeCursorAtEnd()()` Places the cursor at the end of the text. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer.https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer).selectAll()()` Places the selection around all the text. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState.https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldState).setTextAndPlaceCursorAtEnd(kotlin.String)(text: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Sets the text in this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState` to `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldState).setTextAndPlaceCursorAtEnd(kotlin.String)`, replacing any text that was previously there, and places the cursor at the end of the new text. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState.https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldState).setTextAndSelectAll(kotlin.String)(text: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Sets the text in this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState` to `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldState).setTextAndSelectAll(kotlin.String)`, replacing any text that was previously there, and selects all the text. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation.https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).then(androidx.compose.foundation.text.input.InputTransformation)(next: https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation)` Creates a filter chain that will run `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).then(androidx.compose.foundation.text.input.InputTransformation)` after this. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState.https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldState).toTextFieldBuffer()()` Creates a temporary, mutable `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer` representing the current state of this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState`. | Cmn |

## Extension functions

### InputTransformation.allCaps

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/input/InputTransformation.kt+function:allCaps) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0)

```
fun InputTransformation.allCaps(locale: Locale): InputTransformation
```

Returns a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation` that forces all text to be uppercase.

This transformation automatically configures the keyboard to capitalize all characters.

| Parameters |
|---|---|
| `locale: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/intl/Locale` | The `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/intl/Locale` in which to perform the case conversion. |

### InputTransformation.byValue

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/input/InputTransformation.kt+function:byValue)

```
fun InputTransformation.byValue(
    transformation: (current: CharSequence, proposed: CharSequence) -> CharSequence
): InputTransformation
```

Creates an `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation` from a function that accepts both the current and proposed `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldCharSequence` and returns the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldCharSequence` to use for the field.

`https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).byValue(kotlin.Function2)` can return either `current`, `proposed`, or a completely different value.

The selection or cursor will be updated automatically. For more control of selection implement `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation` directly.

```kotlin
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.input.InputTransformation
import androidx.compose.foundation.text.input.TextFieldState
import androidx.compose.foundation.text.input.byValue
import androidx.compose.material3.Text
import androidx.compose.runtime.remember
import androidx.compose.ui.unit.sp

val state = remember { TextFieldState() }
BasicTextField(
    state,
    // Reject whitespace.
    inputTransformation =
        InputTransformation.byValue { current, proposed ->
            if ("""\s""".toRegex() in proposed) current else proposed
        },
)
```

```kotlin
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.input.InputTransformation
import androidx.compose.foundation.text.input.TextFieldState
import androidx.compose.foundation.text.input.byValue
import androidx.compose.material3.Text
import androidx.compose.runtime.remember
import androidx.compose.ui.unit.sp

val state = remember { TextFieldState() }
BasicTextField(
    state,
    // Convert tabs to spaces.
    inputTransformation =
        InputTransformation.byValue { _, proposed ->
            proposed.replace("""\t""".toRegex(), "  ")
        },
)
```

### TextFieldState.clearText

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/input/TextFieldState.kt+function:clearText) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0)

```
fun TextFieldState.clearText(): Unit
```

Deletes all the text in the state.

To perform more complicated edits on the text, call `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState#edit(kotlin.Function1)`. This function is equivalent to calling:

```kotlin
edit {
  delete(0, length)
  placeCursorAtEnd()
}
```

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldState).setTextAndPlaceCursorAtEnd(kotlin.String)` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldState).setTextAndSelectAll(kotlin.String)` |   |

### TextFieldBuffer.delete

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/input/TextFieldBuffer.kt+function:delete) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0)

```
fun TextFieldBuffer.delete(start: Int, end: Int): Unit
```

Delete the text between `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer).delete(kotlin.Int,kotlin.Int)` (inclusive) and `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer).delete(kotlin.Int,kotlin.Int)` (exclusive). Pass 0 as `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer).delete(kotlin.Int,kotlin.Int)` and `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer#length()` as `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer).delete(kotlin.Int,kotlin.Int)` to delete everything in this buffer.

| Parameters |
|---|---|
| `start: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The character offset of the first character to delete. |
| `end: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The character offset of the first character after the deleted range. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer#replace(kotlin.Int,kotlin.Int,kotlin.CharSequence)` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer#append(kotlin.CharSequence)` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer).insert(kotlin.Int,kotlin.String)` |   |

### TextFieldBuffer.ChangeList.forEachChange

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/input/TextFieldBuffer.kt+function:forEachChange) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0)

```
inline fun TextFieldBuffer.ChangeList.forEachChange(
    block: (range: TextRange, originalRange: TextRange) -> Unit
): Unit
```

Iterates over all changes in this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer.ChangeList` in order of their appearance in the text (from the lowest character offset to the highest).

In each iteration, `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer.ChangeList).forEachChange(kotlin.Function2)` receives `range` (the range of the change in the updated `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer`) and `originalRange` (the corresponding range in the original text buffer before any changes).

Avoid modifying text *before* the current `range`. Changes are ordered by character offset, so modifying text earlier in the buffer shifts the current change to a higher index in the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer.ChangeList`. Because this function iterates forward by index, it will mistakenly visit the current change again and skip the newly inserted change.

For example, assume `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer.ChangeList` initially has one change at `5..8`. If `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer.ChangeList).forEachChange(kotlin.Function2)` inserts text at index `0`, a new change at `0..2` is placed at index 0, and the original change is shifted to index 1. As the loop advances to index 1, it visits the original change a second time.

```kotlin
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.input.TextFieldState
import androidx.compose.foundation.text.input.forEachChange
import androidx.compose.foundation.text.input.rememberTextFieldState
import androidx.compose.material3.Text
import androidx.compose.runtime.remember
import androidx.compose.ui.text.substring

// Print a log message every time the text is changed.
BasicTextField(
    state = rememberTextFieldState(),
    inputTransformation = {
        changes.forEachChange { sourceRange, replacedLength ->
            val newString = asCharSequence().substring(sourceRange)
            println("""$replacedLength characters were replaced with "$newString"""")
        }
    },
)
```

| Parameters |
|---|---|
| `block: (range: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange, originalRange: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | The block to be invoked for each change. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer.ChangeList).forEachChangeReversed(kotlin.Function2)` |   |

### TextFieldBuffer.ChangeList.forEachChangeReversed

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/input/TextFieldBuffer.kt+function:forEachChangeReversed) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0)

```
inline fun TextFieldBuffer.ChangeList.forEachChangeReversed(
    block: (range: TextRange, originalRange: TextRange) -> Unit
): Unit
```

Iterates over all changes in this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer.ChangeList` in reverse order of their appearance in the text (from the highest character offset down to the lowest).

In each iteration, `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer.ChangeList).forEachChangeReversed(kotlin.Function2)` receives `range` (the range of the change in the updated `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer`) and `originalRange` (the corresponding range in the original text buffer before any changes).

Unlike `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer.ChangeList).forEachChange(kotlin.Function2)`, you may safely make non-overlapping changes *after* the current `range` without triggering repeated iterations.

Because iteration proceeds backward by index, any new changes made after the current range are assigned greater indices in the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer.ChangeList` and fall beyond the current loop index, so they are cleanly skipped.

For example, suppose `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer.ChangeList` has changes at index 0 (`0..2`) and index 1 (`10..12`). This function visits index 1 first. If you then insert text at index `15`, the new change is appended at index 2. Since the loop next decrements to index 0, the new change at index 2 is skipped.

```kotlin
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.input.TextFieldState
import androidx.compose.foundation.text.input.delete
import androidx.compose.foundation.text.input.forEachChange
import androidx.compose.foundation.text.input.forEachChangeReversed
import androidx.compose.foundation.text.input.insert
import androidx.compose.foundation.text.input.rememberTextFieldState
import androidx.compose.material3.Text
import androidx.compose.runtime.remember

// Make a text field behave in "insert mode" -- inserted text overwrites the text ahead of it
// instead of being inserted.
BasicTextField(
    state = rememberTextFieldState(),
    inputTransformation = {
        changes.forEachChangeReversed { range, originalRange ->
            if (!range.collapsed && originalRange.collapsed) {
                // New text was inserted, delete the text ahead of it.
                delete(
                    range.end.coerceAtMost(length),
                    (range.end + range.length).coerceAtMost(length),
                )
            }
        }
    },
)
```

| Parameters |
|---|---|
| `block: (range: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange, originalRange: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | The block to be invoked for each change. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer.ChangeList).forEachChange(kotlin.Function2)` |   |

### TextFieldBuffer.insert

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/input/TextFieldBuffer.kt+function:insert) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0)

```
fun TextFieldBuffer.insert(index: Int, text: String): Unit
```

Insert `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer).insert(kotlin.Int,kotlin.String)` at the given `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer).insert(kotlin.Int,kotlin.String)` in this value. Pass 0 to insert `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer).insert(kotlin.Int,kotlin.String)` at the beginning of this buffer, and pass `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer#length()` to insert `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer).insert(kotlin.Int,kotlin.String)` at the end of this buffer.

This is equivalent to calling `replace(index, index, text)`.

| Parameters |
|---|---|
| `index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The character offset at which to insert `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer).insert(kotlin.Int,kotlin.String)`. |
| `text: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The text to insert. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer#replace(kotlin.Int,kotlin.Int,kotlin.CharSequence)` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer#append(kotlin.CharSequence)` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer).delete(kotlin.Int,kotlin.Int)` |   |

### InputTransformation.maxLength

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/input/InputTransformation.kt+function:maxLength) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0) Deprecated in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.13.0-rc01)

```
fun InputTransformation.[maxLength](https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).maxLength(kotlin.Int))(maxLength: Int): InputTransformation
```

> [!CAUTION]
> **This function is deprecated.**   
> Use maxLengthTrim to truncate excess characters or maxLengthReject to reject input exceeding maxLength, use this instead:
>
> ```kotlin
> this.maxLengthReject(maxLength)
> ```

Returns `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation` that rejects input which causes the total length of the text field to be more than `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).maxLength(kotlin.Int)` characters.

This transformation also sets the maximum text length for accessibility services. When using an `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/OutputTransformation` that adds decorating characters, the announced maximum length may need to be adjusted to account for those characters. See the linked sample for an example of a custom `maxLength` filter that does this.

```kotlin
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.input.InputTransformation
import androidx.compose.foundation.text.input.OutputTransformation
import androidx.compose.foundation.text.input.TextFieldBuffer
import androidx.compose.foundation.text.input.TextFieldState
import androidx.compose.foundation.text.input.delete
import androidx.compose.foundation.text.input.insert
import androidx.compose.material3.Text
import androidx.compose.runtime.remember
import androidx.compose.ui.semantics.SemanticsPropertyReceiver
import androidx.compose.ui.semantics.maxTextLength

val state = remember { TextFieldState() }
BasicTextField(
    state,
    inputTransformation =
        object : InputTransformation {
            override fun SemanticsPropertyReceiver.applySemantics() {
                // The output transformation formats "1234567890" to "(123) 456-7890",
                // which is 14 characters long. We set the accessibility maximum length
                // to 14 so screen readers announce the correct limit.
                maxTextLength = 14
            }

            override fun TextFieldBuffer.transformInput() {
                if (length > 10) {
                    delete(10, length)
                }
            }
        },
    outputTransformation =
        OutputTransformation {
            if (length > 0) insert(0, "(")
            if (length > 4) insert(4, ") ")
            if (length > 9) insert(9, "-")
        },
)
```

### InputTransformation.maxLengthReject

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/input/InputTransformation.kt+function:maxLengthReject) Added in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.13.0-rc01)

```
fun InputTransformation.maxLengthReject(maxLength: Int): InputTransformation
```

Rejects input changes that would cause the total length of the text field to exceed `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).maxLengthReject(kotlin.Int)` characters.

When text is inserted (e.g. by typing or pasting) that would cause the total length to exceed `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).maxLengthReject(kotlin.Int)`, the entire edit operation is rejected and reverted, leaving the existing text unchanged. For example, pasting "12345" into a text field that already has 8 characters and a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).maxLengthReject(kotlin.Int)` of 10 will reject the paste completely, leaving the original 8 characters unchanged.

This transformation sets the maximum text length for accessibility services. `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/OutputTransformation` does not affect this limit. When using an `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/OutputTransformation` that adds decorating characters, set `https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/package-summary#(androidx.compose.ui.semantics.SemanticsPropertyReceiver).maxTextLength()` manually in a custom `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation` to include those characters in the announced limit.

```kotlin
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.input.InputTransformation
import androidx.compose.foundation.text.input.OutputTransformation
import androidx.compose.foundation.text.input.TextFieldBuffer
import androidx.compose.foundation.text.input.TextFieldState
import androidx.compose.foundation.text.input.delete
import androidx.compose.foundation.text.input.insert
import androidx.compose.material3.Text
import androidx.compose.runtime.remember
import androidx.compose.ui.semantics.SemanticsPropertyReceiver
import androidx.compose.ui.semantics.maxTextLength

val state = remember { TextFieldState() }
BasicTextField(
    state,
    inputTransformation =
        object : InputTransformation {
            override fun SemanticsPropertyReceiver.applySemantics() {
                // The output transformation formats "1234567890" to "(123) 456-7890",
                // which is 14 characters long. We set the accessibility maximum length
                // to 14 so screen readers announce the correct limit.
                maxTextLength = 14
            }

            override fun TextFieldBuffer.transformInput() {
                if (length > 10) {
                    delete(10, length)
                }
            }
        },
    outputTransformation =
        OutputTransformation {
            if (length > 0) insert(0, "(")
            if (length > 4) insert(4, ") ")
            if (length > 9) insert(9, "-")
        },
)
```

### InputTransformation.maxLengthTrim

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/input/InputTransformation.kt+function:maxLengthTrim) Added in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.13.0-rc01)

```
fun InputTransformation.maxLengthTrim(maxLength: Int): InputTransformation
```

Limits the total length of the text field to `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).maxLengthTrim(kotlin.Int)` characters by truncating inserted characters.

When text is inserted (e.g. by typing or pasting) that would cause the total length to exceed `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).maxLengthTrim(kotlin.Int)`, only enough inserted characters are kept to fill the text field up to `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).maxLengthTrim(kotlin.Int)`, and excess characters are trimmed and discarded. For example, pasting "12345" into a text field that already has 8 characters and a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).maxLengthTrim(kotlin.Int)` of 10 will insert only "12", resulting in 10 characters.

This transformation sets the maximum text length for accessibility services. `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/OutputTransformation` does not affect this limit. When using an `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/OutputTransformation` that adds decorating characters, set `https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/package-summary#(androidx.compose.ui.semantics.SemanticsPropertyReceiver).maxTextLength()` manually in a custom `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation` to include those characters in the announced limit.

```kotlin
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.input.InputTransformation
import androidx.compose.foundation.text.input.OutputTransformation
import androidx.compose.foundation.text.input.TextFieldBuffer
import androidx.compose.foundation.text.input.TextFieldState
import androidx.compose.foundation.text.input.delete
import androidx.compose.foundation.text.input.insert
import androidx.compose.material3.Text
import androidx.compose.runtime.remember
import androidx.compose.ui.semantics.SemanticsPropertyReceiver
import androidx.compose.ui.semantics.maxTextLength

val state = remember { TextFieldState() }
BasicTextField(
    state,
    inputTransformation =
        object : InputTransformation {
            override fun SemanticsPropertyReceiver.applySemantics() {
                // The output transformation formats "1234567890" to "(123) 456-7890",
                // which is 14 characters long. We set the accessibility maximum length
                // to 14 so screen readers announce the correct limit.
                maxTextLength = 14
            }

            override fun TextFieldBuffer.transformInput() {
                if (length > 10) {
                    delete(10, length)
                }
            }
        },
    outputTransformation =
        OutputTransformation {
            if (length > 0) insert(0, "(")
            if (length > 4) insert(4, ") ")
            if (length > 9) insert(9, "-")
        },
)
```

### TextFieldBuffer.placeCursorAtEnd

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/input/TextFieldBuffer.kt+function:placeCursorAtEnd) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0)

```
fun TextFieldBuffer.placeCursorAtEnd(): Unit
```

Places the cursor at the end of the text.

### TextFieldBuffer.selectAll

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/input/TextFieldBuffer.kt+function:selectAll) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0)

```
fun TextFieldBuffer.selectAll(): Unit
```

Places the selection around all the text.

### TextFieldState.setTextAndPlaceCursorAtEnd

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/input/TextFieldState.kt+function:setTextAndPlaceCursorAtEnd) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0)

```
fun TextFieldState.setTextAndPlaceCursorAtEnd(text: String): Unit
```

Sets the text in this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState` to `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldState).setTextAndPlaceCursorAtEnd(kotlin.String)`, replacing any text that was previously there, and places the cursor at the end of the new text.

To perform more complicated edits on the text, call `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState#edit(kotlin.Function1)`. This function is equivalent to calling:

```kotlin
edit {
  replace(0, length, text)
  placeCursorAtEnd()
}
```

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldState).setTextAndSelectAll(kotlin.String)` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldState).clearText()` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer).placeCursorAtEnd()` |   |

### TextFieldState.setTextAndSelectAll

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/input/TextFieldState.kt+function:setTextAndSelectAll) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0)

```
fun TextFieldState.setTextAndSelectAll(text: String): Unit
```

Sets the text in this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState` to `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldState).setTextAndSelectAll(kotlin.String)`, replacing any text that was previously there, and selects all the text.

To perform more complicated edits on the text, call `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState#edit(kotlin.Function1)`. This function is equivalent to calling:

```kotlin
edit {
  replace(0, length, text)
  selectAll()
}
```

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldState).setTextAndPlaceCursorAtEnd(kotlin.String)` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldState).clearText()` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.TextFieldBuffer).selectAll()` |   |

### InputTransformation.then

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/input/InputTransformation.kt+function:then) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0)

```
fun InputTransformation.then(next: InputTransformation): InputTransformation
```

Creates a filter chain that will run `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).then(androidx.compose.foundation.text.input.InputTransformation)` after this. Filters are applied sequentially, so any changes made by this filter will be visible to `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).then(androidx.compose.foundation.text.input.InputTransformation)`.

The returned filter will use the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/KeyboardOptions` from `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/package-summary#(androidx.compose.foundation.text.input.InputTransformation).then(androidx.compose.foundation.text.input.InputTransformation)` if non-null, otherwise it will use the options from this transformation.

```kotlin
import androidx.compose.foundation.text.input.InputTransformation
import androidx.compose.foundation.text.input.then

val removeFirstEFilter = InputTransformation {
    val index = asCharSequence().indexOf('e')
    if (index != -1) {
        replace(index, index + 1, "")
    }
}
val printECountFilter = InputTransformation {
    println("found ${asCharSequence().count { it == 'e' }} 'e's in the string")
}

// Returns a filter that always prints 0 e's.
removeFirstEFilter.then(printECountFilter)

// Returns a filter that prints the number of e's before the first one is removed.
printECountFilter.then(removeFirstEFilter)
```

| Parameters |
|---|---|
| `next: https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation` | The `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/InputTransformation` that will be ran after this one. |

### TextFieldState.toTextFieldBuffer

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/input/TextFieldState.kt+function:toTextFieldBuffer) Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0)

```
fun TextFieldState.toTextFieldBuffer(): TextFieldBuffer
```

Creates a temporary, mutable `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer` representing the current state of this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState`.

Use a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer` to:

- Apply transformations for testing purposes

- Preview how the TextField would render with a specific `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/OutputTransformation`

This is similar to calling `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState#edit(kotlin.Function1)`, but without committing the changes back to the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldState`.

**Important:** A `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/input/TextFieldBuffer` is intended for short-term use. Let the garbage collector dispose of it when you're finished to avoid unnecessary memory usage.

```kotlin
import androidx.compose.foundation.text.input.OutputTransformation
import androidx.compose.foundation.text.input.TextFieldBuffer
import androidx.compose.foundation.text.input.TextFieldState
import androidx.compose.foundation.text.input.insert
import androidx.compose.foundation.text.input.toTextFieldBuffer
import androidx.compose.material3.Text

val state = TextFieldState("Hello, World")
val outputTransformation = OutputTransformation { insert(0, "> ") }

val buffer = state.toTextFieldBuffer()
with(outputTransformation) { buffer.transformOutput() }

val transformedText = buffer.asCharSequence()
val transformedSelection = buffer.selection
```