# Class TextInputState

java.lang.Object
com.codename1.ui.TextInputState

public final class TextInputState extends Object

An immutable snapshot of the editing state shared between a `TextInputClient` and the platform text input source. It carries the surrounding text the platform needs for autocorrect / prediction, the current selection, and the in progress IME composition (marked text) range if any.

All offsets are UTF-16 character indices into `text`, matching Java `String` indices as well as the `NSString` / Android `Editable` indices used by the native input machinery. A collapsed selection (`selectionStart == selectionEnd`) represents a plain caret. A composing range of `-1, -1` means no IME composition is active.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TextInputState(String text, int selectionStart, int selectionEnd)`
  Creates a state snapshot without an active composition.
  `TextInputState(String text, int selectionStart, int selectionEnd, int composingStart, int composingEnd)`
  Creates a state snapshot including an IME composition range.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `getComposingEnd()`
  Returns the UTF-16 offset where the IME marked text ends, or -1 when no composition is active.
  `int`
  `getComposingStart()`
  Returns the UTF-16 offset where the IME marked text begins, or -1 when no composition is active.
  `int`
  `getSelectionEnd()`
  Returns the UTF-16 offset of the selection focus.
  `int`
  `getSelectionStart()`
  Returns the UTF-16 offset of the selection anchor.
  `String`
  `getText()`
  Returns the surrounding text.
  `boolean`
  `isCaret()`
  True when the selection is collapsed to a caret.
  `boolean`
  `isComposing()`
  True when an IME composition (marked text) is currently active.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### TextInputState

    public TextInputState(String text, int selectionStart, int selectionEnd)

    Creates a state snapshot without an active composition.

    ###### Parameters

    - `text`: the surrounding text (may be a window around the caret for very large documents)

    - `selectionStart`: UTF-16 offset of the selection anchor

    - `selectionEnd`: UTF-16 offset of the selection focus

  - ### TextInputState

    public TextInputState(String text, int selectionStart, int selectionEnd, int composingStart, int composingEnd)

    Creates a state snapshot including an IME composition range.

    ###### Parameters

    - `text`: the surrounding text

    - `selectionStart`: UTF-16 offset of the selection anchor

    - `selectionEnd`: UTF-16 offset of the selection focus

    - `composingStart`: UTF-16 offset where the marked text begins, or -1 when none

    - `composingEnd`: UTF-16 offset where the marked text ends, or -1 when none

- ## Method Details

  - ### getText

    public String getText()
    Returns the surrounding text.

  - ### getSelectionStart

    public int getSelectionStart()
    Returns the UTF-16 offset of the selection anchor.

  - ### getSelectionEnd

    public int getSelectionEnd()
    Returns the UTF-16 offset of the selection focus.

  - ### getComposingStart

    public int getComposingStart()
    Returns the UTF-16 offset where the IME marked text begins, or -1 when no composition is active.

  - ### getComposingEnd

    public int getComposingEnd()
    Returns the UTF-16 offset where the IME marked text ends, or -1 when no composition is active.

  - ### isCaret

    public boolean isCaret()
    True when the selection is collapsed to a caret.

  - ### isComposing

    public boolean isComposing()
    True when an IME composition (marked text) is currently active.