public final class TextInputState
- Object
- TextInputState
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.
Constructors
public TextInputState(String text, int selectionStart, int selectionEnd) | Creates a state snapshot without an active composition. |
public TextInputState(String text, int selectionStart, int selectionEnd, int composingStart, int composingEnd) | Creates a state snapshot including an IME composition range. |
Methods
public String getText() | Returns the surrounding text. |
public int getSelectionStart() | Returns the UTF-16 offset of the selection anchor. |
public int getSelectionEnd() | Returns the UTF-16 offset of the selection focus. |
public int getComposingStart() | Returns the UTF-16 offset where the IME marked text begins, or -1 when no composition is active. |
public int getComposingEnd() | Returns the UTF-16 offset where the IME marked text ends, or -1 when no composition is active. |
public boolean isCaret() | True when the selection is collapsed to a caret. |
public boolean isComposing() | True when an IME composition (marked text) is currently active. |
Inherited methods
Constructor details
TextInputState
public TextInputState(String text, int selectionStart, int selectionEnd)Creates a state snapshot without an active composition.
Parameters
textString- the surrounding text (may be a window around the caret for very large documents)
selectionStartint- UTF-16 offset of the selection anchor
selectionEndint- 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
textString- the surrounding text
selectionStartint- UTF-16 offset of the selection anchor
selectionEndint- UTF-16 offset of the selection focus
composingStartint- UTF-16 offset where the marked text begins, or -1 when none
composingEndint- 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.