EditorState

The editor state class is a persistent (immutable) data structure. To update a state, you create a Transaction, which produces a new state instance.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The line containing the primary cursor.

Link copied to clipboard

The character position of the primary cursor.

Link copied to clipboard
val doc: Text

The current document.

Link copied to clipboard

Get the proper line-break string for this state.

Link copied to clipboard

Returns true when the editor is configured to be read-only.

Link copied to clipboard

The text currently selected by the primary selection, or empty string for cursors.

Link copied to clipboard

The current selection.

Link copied to clipboard

The size (in columns) of a tab in the document.

Functions

Link copied to clipboard

Create a set of changes and a new selection by running the given function for each range in the active selection.

Link copied to clipboard
fun changes(spec: ChangeSpec? = null): ChangeSet

Create a ChangeSet from the given change description.

Link copied to clipboard

Return a function that can categorize strings into one of: Word, Space, or Other.

Link copied to clipboard

Get the value of a state facet via a FacetReader.

fun <Output> facet(facet: Facet<*, Output>): Output

Get the value of a state facet.

Link copied to clipboard
fun <T> field(field: StateField<T>): T

Retrieve the value of a state field. Throws an error when the state doesn't have that field, unless you pass false as second parameter.

fun <T> field(field: StateField<T>, require: Boolean): T?

Retrieve the value of a state field, or null if the field is not present.

Link copied to clipboard
operator fun <T> get(field: StateField<T>): T

Retrieve the value of a state field using index syntax.

Link copied to clipboard
fun <T> languageDataAt(key: LanguageDataKey<T>, pos: DocPos, side: Int = -1): List<T>

Find the values for a given language data field using a type-safe key.

fun <T> languageDataAt(name: String, pos: DocPos, side: Int = -1): List<T>

Find the values for a given language data field by string name.

Link copied to clipboard
fun phrase(phrase: String, vararg insert: Any): String

Look up a translation for the given phrase.

Link copied to clipboard

Create a transaction spec that replaces every selection range with the given content.

Link copied to clipboard
fun sliceDoc(from: DocPos = DocPos.ZERO, to: DocPos = doc.endPos): String

Return the given range of the document as a string.

Link copied to clipboard

Serialize this state to an EditorStateData.

Link copied to clipboard
fun toJSON(fields: Map<String, StateField<*>>? = null): Map<String, Any?>

Convert this state to a JSON-serializable object.

Link copied to clipboard
fun toText(string: String): Text

Using the state's line separator, create a Text instance from the given string.

Link copied to clipboard
fun update(vararg specs: TransactionSpec): Transaction

Create a Transaction that updates this state.

Link copied to clipboard

Find the word at the given position.