SpellCheckingTextEditor

fun SpellCheckingTextEditor(spellChecker: EditorSpellChecker? = null, state: SpellCheckState = rememberSpellCheckState(spellChecker), modifier: Modifier = Modifier, contentPadding: PaddingValues = DefaultContentPadding, enabled: Boolean = true, autoFocus: Boolean = false, style: TextEditorStyle = rememberTextEditorStyle(), contextMenuStrings: ContextMenuStrings = ContextMenuStrings.Default, spellCheckStrings: SpellCheckStrings = SpellCheckStrings.Default, onAddToDictionary: (String) -> Unit? = null, spellCheckMenuItems: (SpellCheckItem) -> List<ContextMenuItem> = { emptyList() }, diagnostics: TextDiagnosticsState? = null, onRichSpanClick: RichSpanClickListener? = null, onRichSpanClickEvent: RichSpanClickEventListener? = null, onLinkClick: (url: String) -> Unit? = null, keyBindings: KeyBindings = LocalKeyBindings.current, contentDescription: String? = null, readOnly: Boolean = false, lineLimits: EditorLineLimits = EditorLineLimits.Fill, softWrap: Boolean = true)(source)

A drop-in text editor composable with integrated spell checking.

Wraps BasicTextEditor and overlays spell-check decorations driven by a SpellCheckState. Edits are observed reactively: affected spans are invalidated immediately and re-checked once typing goes quiet, and replacing the document wholesale re-checks all of it. Secondary clicks and taps on a flagged span open a context menu of Suggestions for the misspelled word or sentence-level Correction, as do Shift+F10 and the Menu key with the caret in one.

Parameters

spellChecker

The EditorSpellChecker backing spell checks; used to build a default state when none is provided. May be null to disable checking.

state

The SpellCheckState coordinating spell checking over the underlying TextEditorState. Defaults to a remembered state built from spellChecker.

modifier

The Modifier applied to the editor surface.

contentPadding

Padding applied around the editor content.

enabled

Whether the editor accepts input and focus. A disabled editor offers no spell check menu.

readOnly

Shows the caret for navigation and selection but takes no edits; see BasicTextEditor. The menu on a flagged span offers Ignore, Add to dictionary and spellCheckMenuItems, but no corrections or fixes.

lineLimits

Fills the height given, grows with the text between a minimum and maximum number of lines, or keeps it to one row that scrolls sideways; see BasicTextEditor.

autoFocus

Whether the editor requests focus on first composition.

style

The TextEditorStyle controlling appearance.

contextMenuStrings

Localized strings for the built-in context menu.

spellCheckStrings

Localized strings for the spell check menu.

onAddToDictionary

Adds a word to the host's dictionary. When set, the menu on a flagged word offers "Add to dictionary", which calls this and stops flagging the word for the session, so it clears at once however the host's dictionary reaches the checker. It receives the word as flagged, capitals included; the session matches it across case as SpellCheckState.ignoreWord does.

spellCheckMenuItems

Host items for the context menu opened on a flagged span, rendered after the built-in "Ignore" and "Add to dictionary" in a group below the suggestions. For a misspelled word they appear together with the suggestions once those have loaded. Not consulted while the editor is disabled. Read when the menu opens, so it may close over changing state.

diagnostics

Underlines from a checker other than spelling, such as grammar, kept up to date as the text changes. Its TextDiagnosticsState.textState must be state's. A secondary click or tap on one, or Shift+F10 or the Menu key with the caret in it, opens a menu of its message and fixes.

onRichSpanClick

Optional listener for clicks on other rich spans; spell-check and diagnostic spans are handled internally.

onRichSpanClickEvent

The same clicks as onRichSpanClick, with the modifier keys that were held.

onLinkClick

Opens a link's URL on Ctrl+click, or Cmd+click under the macOS keyBindings; see BasicTextEditor.

keyBindings

Chord-to-command mapping, defaulting to LocalKeyBindings.

contentDescription

The editor's label for accessibility services; see BasicTextEditor.

softWrap

Whether lines wrap at the editor's width; with false a line stays one row and the editor scrolls sideways. See BasicTextEditor.