In its most basic form, an editor's state is made up of a current document and a selection. Because there are a lot of extra pieces that an editor might need to keep in its state (such as an undo history or syntax tree), it is possible for extensions to add additional fields to the state object.
@EditorStateConfig
@EditorState
@SelectionRange
@EditorSelection
@CharCategory
The Text
type stores documents in an immutable tree-shaped
representation that allows:
-
Efficient indexing both by code unit offset and by line number.
-
Structure-sharing immutable updates.
-
Access to and iteration over parts of the document without copying or concatenating big strings.
Line numbers start at 1. Character positions are counted from zero, and count each line break and UTF-16 code unit as one unit.
@Text
@Line
@TextIterator
@countColumn
@findColumn
If you support environments that don't yet have String.fromCodePoint
and codePointAt
, this package provides portable replacements for them.
@codePointAt
@fromCodePoint
@codePointSize
@findClusterBreak
CodeMirror treats changes to the document as objects, which are usually part of a transaction.
This is how you'd make a change to a document (replacing “world” with “editor”) and create a new state with the updated document:
let state = EditorState.create({doc: "hello world"})
let transaction = state.update({changes: {from: 6, to: 11, insert: "editor"}})
console.log(transaction.state.doc.toString()) // "hello editor"
@TransactionSpec
@ChangeSpec
@Transaction
@ChangeDesc
@MapMode
@ChangeSet
@Annotation
@AnnotationType
@StateEffect
@StateEffectType
The following are some types and mechanisms used when writing extensions for the editor state.
@StateCommand
@Extension
@StateField
@Facet
@FacetReader
@Prec
@Compartment
Range sets provide a data structure that can hold a collection of tagged, possibly overlapping ranges in such a way that they can efficiently be mapped though document changes. They are used for storing things like decorations or gutter markers.
@RangeValue
@Range
@RangeSet
@RangeCursor
@RangeSetBuilder
@RangeComparator
@SpanIterator
@combineConfig