Operation
An operation is the lowest-level description of a specific change to a part of Slate's value. They are designed to be collaborative-editing friendly.
All of the Change
methods result in operations being created and applied to a Value
They're accessible via the change.operations
property.
There are a handful of Slate operation types. The goal is to have the fewest possible types, while still maintaining the necessary semantics for collaborative editing to work.
Text Operations
insert_text
insert_text
Inserts a text
string at offset
into a text node at path
, with optional marks
to be applied to the inserted characters.
remove_text
remove_text
Removes a string of text
at offset
into a text node at path
.
Mark Operations
add_mark
add_mark
Adds a mark
to the text node at path
starting at an offset
and spanning length
characters.
remove_mark
remove_mark
Removes a mark
from a text node at path
starting at an offset
and spanning length
characters.
set_mark
set_mark
Set new properties
on any marks that match an existing mark
in a text node at path
, starting at an offset
and spanning length
characters.
Node Operations
insert_node
insert_node
Insert a new node
at path
.
merge_node
merge_node
Merge the node at path
with its previous sibling. The position
refers to either the index in the child nodes of the previous sibling in the case of Block
or Inline
nodes, and the index in the characters of the previous sibling in the case of Text
nodes. The properties
object contains properties of the merged node in the event that the change is undone.
move_node
move_node
Move the node at path
to a newPath
.
remove_node
remove_node
Remove the node at path
.
set_node
set_node
Set new properties
on the node at path
.
split_node
split_node
Split the node at path
at position
. The position
refers to either the index in the child nodes in the case of Block
or Inline
nodes, and the index in the characters in the case of Text
nodes. In the case of nested splits, target
refers to the target path of the child split operation. The properties
object contains properties that should be assigned to the new node created after the split operation is complete.
Value Operations
set_selection
set_selection
Set new properties
on the selection.
set_value
set_value
Set new properties
on a value. Properties can contain data
and decorations
.
Helpers
apply
apply
apply(value: Value, operation: Object) => Value
Applies an operation
to a value
object.
invert
invert
invert(operation: Object) => Object
Create an inverse operation that will undo the changes made by the original.
Last updated