TypingContext

data class TypingContext

It’s important to note that the cursorStart and cursorEnd refer to the character position of the cursor in the text, as reflected by the following examples (where the character | marks the position(s) of the cursor):

  • “Hello world|” -> TypingContext(context: “Hello world”, cursor: 11)
  • “Hello šŸŒŽ|” -> TypingContext(context: “Hello šŸŒŽ”, cursor: 7)
  • “č²«|” -> TypingContext(context: “č²«”, cursor: 1)
  • “FaƧade and EntrepĆ“t|” -> TypingContext(context: “FaƧade and EntrepĆ“t”, cursor: 19)

Take into account that these positions do not always match the selectionStart and selectionEnd of the EditText, specially whe there are special characters such as emoji, diacritics, etc.

Summary

Constructors
TypingContext(context: String)
TypingContext(context: String, cursor: Int)
TypingContext(context: String, cursorStart: Int, cursorEnd: Int)
Properties
String context
The text context.
Int cursorStart
The position of the start of the cursor with respect to the context.
Int cursorEnd
The position of the end of the cursor with respect to the context.

Constructor

TypingContext

TypingContext(context: String)
Parameters
context: String The text context.

TypingContext

TypingContext(context: String, cursor: Int)

Initializes the TypingContext with the cursor position.
Example: “Hello |wrld” => context=“Hello wrld”, cursor=6.

Parameters
context: String The text context.
cursor: Int The position of the cursor with respect to the ‘context’.

TypingContext

TypingContext(context: String, cursorStart: Int, cursorEnd: Int)

Initializes the ‘TypingContext’ allowing a selection of a substring in the text context.
Example: “Hello |wrld|” => context=“Hello wrld”, cursorStart=6, cursorEnd=10. This means that “wrld” is selected.

Parameters
context: String The text context.
cursorStart: Int The position of the start of the cursor with respect to the context.
cursorEnd: Int The position of the end of the cursor with respect to the context.

Properties

context

val context: String

The text context.

cursorStart

var cursorStart: Int = context.length

The position of the start of the cursor with respect to the context.

cursorEnd

var cursorEnd: Int = context.length

The position of the end of the cursor with respect to the context. cursorEnd should always be greater than or equal to cursorStart.


If something needs to be added or if you find an error in our documentation, please let us know either on our GitHub or Discord.

Last updated on August 9, 2022