Class 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.
-
Constructor Summary
ConstructorsConstructorDescriptionTextInputState(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 TypeMethodDescriptionintReturns the UTF-16 offset where the IME marked text ends, or -1 when no composition is active.intReturns the UTF-16 offset where the IME marked text begins, or -1 when no composition is active.intReturns the UTF-16 offset of the selection focus.intReturns the UTF-16 offset of the selection anchor.getText()Returns the surrounding text.booleanisCaret()True when the selection is collapsed to a caret.booleanTrue when an IME composition (marked text) is currently active.
-
Constructor Details
-
TextInputState
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
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.
-