Package-level declarations

Types

Link copied to clipboard
class Annotation<T>

Annotations are tagged values that are used to add metadata to transactions in an extensible way.

Link copied to clipboard

Marker that identifies a type of Annotation.

Link copied to clipboard
data class ChangeByRangeResult(val range: SelectionRange, val changes: ChangeSpec? = null, val effects: List<StateEffect<*>>? = null)
Link copied to clipboard
open class ChangeDesc

A change description is a variant of ChangeSet that doesn't store the inserted text. As such, it can't be applied, but is cheaper to store and manipulate.

Link copied to clipboard
sealed interface ChangeFilterResult
Link copied to clipboard

A change set represents a group of modifications to a document. It stores the document length, and can only be applied to documents with exactly that length.

Link copied to clipboard
sealed interface ChangeSetJsonPart
Link copied to clipboard
sealed interface ChangeSpec

This type is used as argument to EditorState.changes and in the changes field of transaction specs to succinctly describe document changes.

Link copied to clipboard

The categories produced by a character categorizer. These are used to do things like selecting by word.

Link copied to clipboard

Extension compartments can be used to make a configuration dynamic.

Link copied to clipboard
data class CompartmentReconfigure(val compartment: Compartment, val extension: Extension)
Link copied to clipboard
value class DocPos(val value: Int) : Comparable<DocPos>

A document position represented as a 0-based character offset.

Link copied to clipboard
sealed interface DocSpec
Link copied to clipboard

An editor selection holds one or more selection ranges.

Link copied to clipboard
@Serializable
data class EditorSelectionData(val ranges: List<SelectionRangeData>, val main: Int)

Serializable representation of an EditorSelection.

Link copied to clipboard

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

Link copied to clipboard

Builder scope for constructing an EditorState via DSL.

Link copied to clipboard
data class EditorStateConfig(val doc: DocSpec? = null, val selection: SelectionSpec? = null, val extensions: Extension? = null)

Options passed when creating an editor state.

Link copied to clipboard
@Serializable
data class EditorStateData(val doc: String, val selection: EditorSelectionData, val fields: Map<String, JsonElement> = emptyMap())

Serializable representation of an EditorState.

Link copied to clipboard
annotation class EditorStateDsl

Marks DSL scope for EditorStateBuilder to prevent accidental scope leaking.

Link copied to clipboard
interface Extension

Extension values can be provided when creating a state to attach various kinds of configuration and behavior information. Extensions can be nested in arrays arbitrarily deep.

Link copied to clipboard
class ExtensionHolder(val extension: Extension) : Extension
Link copied to clipboard
class ExtensionList(val extensions: List<Extension>) : Extension
Link copied to clipboard

Builder scope for assembling a list of extensions using unary +.

Link copied to clipboard
Link copied to clipboard
sealed interface FacetEnabler<Input, Output>

A facet is a labeled value that is associated with an editor state. It takes inputs from any number of extensions, and combines those into a single output value.

Link copied to clipboard
data class FacetReader<Output>(val id: Int, val default: Output)

A facet reader can be used to fetch the value of a facet.

Link copied to clipboard
sealed interface FieldSerialization<V>

Describes how a StateField's value is serialized to/from JSON.

Link copied to clipboard
data class FilterResult(val changes: ChangeSet, val filtered: ChangeDesc)
Link copied to clipboard
sealed interface InsertContent
Link copied to clipboard
data class LanguageDataEntry<T>(val key: LanguageDataKey<T>, val value: T)

A type-safe entry pairing a LanguageDataKey with its value.

Link copied to clipboard
class LanguageDataKey<T>(val name: String)

A type-safe key for language data fields.

Link copied to clipboard
class LanguageDataMap(data: Map<String, Any?>)

A type-safe wrapper around language data maps.

Link copied to clipboard
class Line

This type describes a line in the document. It is created on-demand when lines are queried.

Link copied to clipboard
value class LineNumber(val value: Int) : Comparable<LineNumber>

A 1-based line number in a document.

Link copied to clipboard

Distinguishes different ways in which positions can be mapped.

Link copied to clipboard
object Prec

By default extensions are registered in the order they are found. Individual extension values can be assigned a precedence to override this.

Link copied to clipboard
class Range<out T : RangeValue>

A range associates a value with a range of positions.

Link copied to clipboard

Collection of methods used when comparing range sets.

Link copied to clipboard
interface RangeCursor<T>

A range cursor is an object that moves to the next range every time you call next on it.

Link copied to clipboard

A range set stores a collection of Ranges in a way that makes them efficient to map and update. This is an immutable data structure.

Link copied to clipboard

A range set builder is a data structure that helps build up a RangeSet directly, without first allocating an array of Range objects.

Link copied to clipboard
class RangeSetUpdate<T : RangeValue>(val add: List<Range<T>> = emptyList(), val sort: Boolean = false, val filter: (from: Int, to: Int, value: T) -> Boolean? = null, val filterFrom: Int = 0, val filterTo: Int = Int.MAX_VALUE)

Specification for updating a range set.

Link copied to clipboard
abstract class RangeValue

Each range is associated with a value, which must inherit from this class.

Link copied to clipboard

A single selection range. When allowMultipleSelections is enabled, a selection may hold multiple ranges. By default, selections hold exactly one range.

Link copied to clipboard
@Serializable
data class SelectionRangeData(val anchor: Int, val head: Int)

Serializable representation of a SelectionRange.

Link copied to clipboard
sealed interface SelectionSpec
Link copied to clipboard
data class SetFieldHandle<T>(val field: StateField<Set<T>>, val add: StateEffectType<T>, val remove: StateEffectType<T>, val clear: StateEffectType<Unit>)

A handle grouping a StateField with associated StateEffectTypes for a set-based pattern.

Link copied to clipboard
sealed class Slot
Link copied to clipboard

Methods used when iterating over the spans created by a set of ranges.

Link copied to clipboard
typealias StateCommand = (target: StateCommandTarget) -> Boolean

Subtype of Command that doesn't require access to the actual editor view.

Link copied to clipboard
data class StateCommandTarget(val state: EditorState, val dispatch: (Transaction) -> Unit)
Link copied to clipboard

State effects can be used to represent additional effects associated with a transaction.

Link copied to clipboard

Representation of a type of state effect.

Link copied to clipboard

Fields can store additional information in an editor state, and keep it in sync with the rest of the state.

Link copied to clipboard

Builder scope for defining a StateField via DSL.

Link copied to clipboard
annotation class StateFieldDsl

Marks DSL scope for StateFieldBuilder to prevent accidental scope leaking.

Link copied to clipboard
data class StateFieldSpec<Value>(val create: (EditorState) -> Value, val update: (Value, Transaction) -> Value, val compare: (Value, Value) -> Boolean? = null, val provide: (StateField<Value>) -> Extension? = null, val serialization: FieldSerialization<Value> = FieldSerialization.none())
Link copied to clipboard
abstract class Text

The data structure for documents.

Link copied to clipboard
interface TextIterator

A text iterator iterates over a sequence of strings. When iterating over a Text document, result values will either be lines or line breaks.

Link copied to clipboard
data class ToggleFieldHandle(val field: StateField<Boolean>, val toggle: StateEffectType<Unit>, val set: StateEffectType<Boolean>)

A handle grouping a StateField with its associated StateEffectTypes for a boolean toggle pattern.

Link copied to clipboard
Link copied to clipboard

Changes to the editor state are grouped into transactions.

Link copied to clipboard
annotation class TransactionDsl

Marks DSL scope for TransactionSpecBuilder to prevent accidental scope leaking.

Link copied to clipboard
data class TransactionExtenderResult(val effects: List<StateEffect<*>>? = null, val annotations: List<Annotation<*>>? = null)

Result type for transaction extender facet.

Link copied to clipboard
sealed interface TransactionFilterResult
Link copied to clipboard
data class TransactionSpec(val changes: ChangeSpec? = null, val selection: SelectionSpec? = null, val effects: List<StateEffect<*>>? = null, val annotations: List<Annotation<*>>? = null, val userEvent: String? = null, val scrollIntoView: Boolean = false, val filter: Boolean? = null, val sequential: Boolean = false)

Describes a Transaction when calling EditorState.update.

Link copied to clipboard

Builder scope for constructing a TransactionSpec via DSL.

Properties

Link copied to clipboard

Facet that controls whether the editor allows multiple selections. When any provider supplies true, multiple selections are enabled.

Link copied to clipboard

Facet that registers change filters. Each filter is called with a transaction and can accept, reject, or restrict the ranges affected by the change.

Link copied to clipboard
Link copied to clipboard

The position at the end of this document.

Link copied to clipboard

Facet that registers inverted effect providers. Each provider maps a transaction to a list of effects that should be applied when the transaction is undone, enabling custom undo/redo behavior for state effects.

Link copied to clipboard

Facet that registers language data providers. Each provider receives the editor state, a position, and a side hint, and returns a list of property maps describing language-specific data (e.g. autocomplete, indentation rules) at that position.

Link copied to clipboard

Facet that configures the line separator used by the editor. When not provided, the editor auto-detects the separator from the document content. Only the first provided value is used.

Link copied to clipboard

Facet that makes the editor read-only. When the first provided value is true, the editor rejects user changes.

Link copied to clipboard
val StateJson: Json

Default Json instance used for state serialization.

Link copied to clipboard

Facet that registers transaction extenders. Each extender can add additional effects or annotations to a transaction after filters have run. Returns null to leave the transaction unchanged.

Link copied to clipboard

Facet that registers transaction filters. Each filter can modify or replace a transaction before it is applied to the state. Filters can return either a modified transaction or a list of transaction specs.

Functions

Link copied to clipboard

Create a SelectionSpec placing the cursor at pos.

Link copied to clipboard
Link copied to clipboard

Convert this String to an InsertContent for use in ChangeSpec.Single.

Link copied to clipboard

Return a Sequence of all Ranges in this set, in order.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun checkSelection(selection: EditorSelection, docLength: Int)
Link copied to clipboard
fun codePointAt(str: String, pos: Int): Int

Find the code point at the given position in a string (like the codePointAt(https://developer.mozilla.org/en-US/docs/Web/JavaScript/ Reference/Global_Objects/String/codePointAt) string method).

Link copied to clipboard
fun codePointSize(code: Int): Int

The amount of positions a character takes up in a Kotlin string.

Link copied to clipboard
fun <Config> combineConfig(configs: List<Map<String, Any?>>, defaults: Map<String, Any?>, combine: Map<String, (Any?, Any?) -> Any?> = emptyMap()): Map<String, Any?>

Utility function for combining behaviors to fill in a config object from an array of provided configs. defaults should hold default values for all optional fields in the config.

Link copied to clipboard
fun countColumn(string: String, tabSize: Int, to: Int = string.length): Int

Count the column position at the given offset into the string, taking extending characters and tab size into account.

Link copied to clipboard

Define a StateField using a DSL builder.

Link copied to clipboard

Create an EditorState using a DSL builder.

Link copied to clipboard
fun extensionListOf(vararg extensions: Extension): ExtensionList

Create an ExtensionList from the given extensions.

Link copied to clipboard
fun <T : RangeValue> RangeSet<T>.filter(predicate: (Range<T>) -> Boolean): RangeSet<T>

Return a new RangeSet containing only the ranges that match predicate.

Link copied to clipboard
fun findClusterBreak(str: String, pos: Int, forward: Boolean = true, includeExtending: Boolean = true): Int

Returns a next grapheme cluster break after (not equal to) pos, if forward is true, or before otherwise. Returns pos itself if no further cluster break is available in the string. Moves across surrogate pairs, extending characters (when includeExtending is true), characters joined with zero-width joiners, and flag emoji.

Link copied to clipboard
fun findColumn(string: String, col: Int, tabSize: Int, strict: Boolean = false): Int

Find the offset that corresponds to the given column position in a string, taking extending characters and tab size into account. By default, the string length is returned when it is too short to reach the column. Pass strict true to make it return -1 in that situation.

Link copied to clipboard
fun <T : RangeValue> RangeSet<T>.forEach(action: (Range<T>) -> Unit)

Iterate over all ranges in this set in order, calling action for each.

Link copied to clipboard

Given a Unicode codepoint, return the Kotlin string that represents it (like String.fromCodePoint(https://developer.mozilla.org/en-US/docs/ Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)).

Link copied to clipboard
fun EditorState.Companion.fromData(data: EditorStateData, config: EditorStateConfig = EditorStateConfig(), fields: Map<String, StateField<*>>? = null): EditorState

Deserialize an EditorState from its EditorStateData representation.

Link copied to clipboard
operator fun <T> StateField<T>.getValue(thisRef: EditorState, property: KProperty<*>): T

Property delegate for reading a StateField value from EditorState.

Link copied to clipboard

Query whether the given character has a Grapheme_Cluster_Break value of Extend in Unicode.

Link copied to clipboard

Build a LanguageDataMap from type-safe entries.

Link copied to clipboard
Link copied to clipboard
operator fun Extension.plus(other: Extension): ExtensionList

Combine two extensions into an ExtensionList.

Link copied to clipboard
inline fun <T : RangeValue> rangeSetOf(block: RangeSetBuilder<T>.() -> Unit): RangeSet<T>

Build a RangeSet using the RangeSetBuilder DSL.

Link copied to clipboard
fun <T> setField(default: Set<T> = emptySet()): SetFieldHandle<T>

Create a StateField backed by a Set with add, remove, and clear effects.

Link copied to clipboard

Convert this selection to a serializable EditorSelectionData.

Convert this range to a serializable SelectionRangeData.

Serialize this state to an EditorStateData.

Link copied to clipboard

Restore an EditorSelection from its serializable representation.

Link copied to clipboard
fun toggleField(default: Boolean = false): ToggleFieldHandle

Create a boolean StateField with toggle and set effects.

Link copied to clipboard

Restore a SelectionRange from its serializable representation.

Link copied to clipboard

Create a TransactionSpec using a DSL builder.