Selection
abstractSuperclass for editor selections. Every selection type should extend this. Should not be instantiated directly.
§Constructors
§Properties
The resolved anchor of the selection (the side that stays in place when the selection is modified).
The resolved head of the selection (the side that moves when the selection is modified).
The ranges covered by the selection.
The resolved lower bound of the selection's main range.
The resolved upper bound of the selection's main range.
Controls whether, when a selection of this type is active in the
browser, the selected range should be visible to the user.
Defaults to true
.
§Methods
Get a bookmark for this selection, which is a value that can be mapped without having access to a current document, and later resolved to a real selection for a given document again. (This is used mostly by the history to track and restore old selections.) The default implementation of this method just converts the selection to a text selection and returns the bookmark for that.
Replace the selection with a slice or, if no slice is given, delete the selection. Will append to the given transaction.
Convert the selection to a JSON representation. When implementing
this for a custom selection class, make sure to give the object a
type
property whose value matches the ID under which you
registered your class.
§Static Methods
Find the cursor or leaf node selection closest to the start of
the given document. Will return an
AllSelection
if no valid position
exists.
Find a valid cursor or leaf node selection starting at the given
position and searching back if dir
is negative, and forward if
positive. When textOnly
is true, only consider cursor
selections. Will return null when no valid selection position is
found.
To be able to deserialize selections from JSON, custom selection classes must register themselves with an ID string, so that they can be disambiguated. Try to pick something that's unlikely to clash with classes from other modules.