SyntaxHighlightedTextField

fun SyntaxHighlightedTextField(value: TextFieldValue, onValueChange: (TextFieldValue) -> Unit, language: Language, modifier: Modifier = Modifier, theme: SyntaxTheme = LocalSyntaxTheme.current, textStyle: TextStyle = LocalTextStyle.current.copy(fontFamily = FontFamily.Monospace), enabled: Boolean = true, readOnly: Boolean = false, cursorBrush: Brush = SolidColor(MaterialTheme.colorScheme.primary), singleLine: Boolean = false, maxLines: Int = Int.MAX_VALUE, minLines: Int = 1, keyboardOptions: KeyboardOptions = KeyboardOptions.Default, keyboardActions: KeyboardActions = KeyboardActions.Default, interactionSource: MutableInteractionSource? = null)

Renders an editable, syntax-highlighted code surface backed by IncrementalHighlighter.

A single BasicTextField owns the one and only text layout, cursor, selection, and IME. Highlighting is painted onto that same layout by a rememberSyntaxHighlightVisualTransformation, so glyph metrics, caret position, and color are always measured from one layout — there is no second layer to drift against. The highlight is computed asynchronously and may lag the caret by a few frames; the caret position itself is always exact.

For non-Material3 chrome or custom layouts, use rememberSyntaxHighlightVisualTransformation directly on your own BasicTextField.

Parameters

value

Source of truth for the editable text and selection.

onValueChange

Invoked with the updated TextFieldValue on every edit.

language

Tree-sitter Language driving the highlighting.

theme

Maps capture names to androidx.compose.ui.text.SpanStyles. Defaults to the value of LocalSyntaxTheme.

textStyle

Base text style; applied to the field and inherited by the highlight spans.

enabled

Whether the field accepts input. Defaults to true.

readOnly

Whether the field's contents can be modified. Defaults to false.

cursorBrush

Caret brush. Defaults to the Material3 primary colour.

singleLine

Defaults to false — code-editor flow.

maxLines

Defaults to unbounded.

minLines

Defaults to 1.

keyboardActions

Callbacks invoked for IME actions (e.g. Done, Next). Defaults to none.