The Android Developer Challenge is back! Submit your idea before December 2.

EditingBuffer

class EditingBuffer
kotlin.Any
   ↳ androidx.ui.input.EditingBuffer

The editing buffer

This class manages the all editing relate states, editing buffers, selection, styles, etc.

Summary

Public constructors

<init>(initialText: String, initialSelection: TextRange)

The editing buffer

Public methods

Unit

Removes the ongoing composition text and reset the composition range.

Unit

Commits the ongoing composition text and reset the composition range.

Unit
delete(start: Int, end: Int)

Remove the given range of text.

operator Char
get(index: Int)

[] operator for the character at the index.

Boolean

Helper function that returns true if the editing buffer has composition text

Unit
replace(start: Int, end: Int, text: String)

Replace the text and move the cursor to the end of inserted text.

Unit
setComposition(start: Int, end: Int)

Mark the specified area of the text as composition text.

Unit
setSelection(start: Int, end: Int)

Mark the specified area of the text as selected text.

String

Properties

Int

The exclusive composition end offset

Int

The inclusive composition start offset

Int

Helper accessor for cursor offset

Int

Returns the length of the buffer.

Int

The exclusive selection end offset

Int

The inclusive selection start offset

Public constructors

<init>

EditingBuffer(
    initialText: String,
    initialSelection: TextRange)

The editing buffer

This class manages the all editing relate states, editing buffers, selection, styles, etc.

Public methods

cancelComposition

fun cancelComposition(): Unit

Removes the ongoing composition text and reset the composition range.

commitComposition

fun commitComposition(): Unit

Commits the ongoing composition text and reset the composition range.

delete

fun delete(
    start: Int,
    end: Int
): Unit

Remove the given range of text.

Different from replace method, this doesn't move cursor location to the end of modified text. Instead, preserve the selection with adjusting the deleted text.

get

operator fun get(index: Int
): Char

[] operator for the character at the index.

hasComposition

fun hasComposition(): Boolean

Helper function that returns true if the editing buffer has composition text

replace

fun replace(
    start: Int,
    end: Int,
    text: String
): Unit

Replace the text and move the cursor to the end of inserted text.

This function cancels selection if there.

Exceptions
IndexOutOfBoundsException if start or end offset is outside of current buffer
IllegalArgumentException if start is larger than end. (reversed range)

setComposition

fun setComposition(
    start: Int,
    end: Int
): Unit

Mark the specified area of the text as composition text.

The empty range or reversed range is not allowed. Use clearComposition in case of clearing composition.

Parameters
start: Int = null: Int the inclusive start offset of the composition
end: Int = null: Int the exclusive end offset of the composition
Exceptions
IndexOutOfBoundsException if start or end offset is ouside of current buffer
IllegalArgumentException if start is larger than or equal to end. (reversed or collapsed range)

setSelection

fun setSelection(
    start: Int,
    end: Int
): Unit

Mark the specified area of the text as selected text.

You can set cursor by specifying the same value to start and end. The reversed range is not allowed.

Parameters
start: Int = null: Int the inclusive start offset of the selection
end: Int = null: Int the exclusive end offset of the selection
Exceptions
IndexOutOfBoundsException if start or end offset is outside of current buffer.
IllegalArgumentException if start is larger than end. (reversed range)

toString

fun toString(): String

Properties

compositionEnd

var compositionEnd: Int

The exclusive composition end offset

If there is no composing text, returns -1

compositionStart

var compositionStart: Int

The inclusive composition start offset

If there is no composing text, returns -1

cursor

var cursor: Int

Helper accessor for cursor offset

length

val length: Int

Returns the length of the buffer.

selectionEnd

var selectionEnd: Int

The exclusive selection end offset

selectionStart

var selectionStart: Int

The inclusive selection start offset