Operations are the granular actions Slate records while an update changes the document, selection, or persistent state. One command can produce many operations.
Replay Operations
editor.update((tx) => {
tx.operations.replay([
{
type: "insert_text",
path: [0, 0],
offset: 15,
text: "A new string of text to be inserted.",
},
{
type: "remove_node",
path: [0, 0],
node: {
text: "A line of text!",
},
},
{
type: "set_selection",
properties: {
anchor: { path: [0, 0], offset: 0 },
},
newProperties: {
anchor: { path: [0, 0], offset: 15 },
},
},
]);
});editor.update((tx) => {
tx.operations.replay([
{
type: "insert_text",
path: [0, 0],
offset: 15,
text: "A new string of text to be inserted.",
},
{
type: "remove_node",
path: [0, 0],
node: {
text: "A line of text!",
},
},
{
type: "set_selection",
properties: {
anchor: { path: [0, 0], offset: 0 },
},
newProperties: {
anchor: { path: [0, 0], offset: 15 },
},
},
]);
});Slate converts editor method calls into low-level operations and applies those operations during the transaction. You usually think about operations when implementing operation replay, history, or import/export tooling.
Bulk edits can still be one operation. For example, paste can produce a
replace_fragment operation that replaces a child slice and moves the model
selection to the end of the inserted fragment. Sync adapters can replay that
operation directly, or translate it into their own representation at the
adapter boundary.
Operations are the replay boundary. They make changes portable enough for history, sync adapters, tests, and persistence tools to inspect or replay.
On This Page
Replay Operations