Editor Transforms

API reference for editor transformation operations in Slate.

Editor transforms are methods that modify the editor state. They are grouped into several categories: node operations, text operations, selection operations, DOM operations, and history operations.

editor.tf

insertFragment

Insert a fragment of nodes at the specified location or current selection.

Parameters

Collapse all

    The nodes to insert.

    Options for the insertion:

    .

    batchDirty: Whether to batch dirty operations

    .

    hanging: Whether the insertion is hanging

    .

    at: Location where to perform insertion

    .

    voids: Whether to allow insertion in void nodes

insertNode

Atomically insert a node at the specified location or current selection.

Parameters

Collapse all

    The node to insert.

    Options for the insertion:

    .

    batchDirty: Whether to batch dirty operations

    .

    hanging: Whether insertion is hanging

    .

    nextBlock: Insert after current block

    .

    removeEmpty: Remove current block if empty

    .

    select: Select inserted nodes

insertNodes

Atomically inserts multiple nodes at the specified location or current selection.

Parameters

Collapse all

    A single node or array of nodes to insert.

    Options for insertion:

replaceNodes

Replace nodes at a location with new nodes.

Parameters

Collapse all

    The replacement nodes.

    Options for the replacement:

setNodes

Set properties of nodes at the specified location.

Parameters

Collapse all

    The properties to set.

    Options for setting properties:

unsetNodes

Unset properties of nodes at the specified location.

Parameters

Collapse all

    The properties to unset.

    Options for unsetting properties:

wrapNodes

Wrap nodes at the specified location in an element container.

Parameters

Collapse all

    The wrapping element.

    Options for wrapping:

unwrapNodes

Unwrap nodes at the specified location.

Parameters

Collapse all

    Options for unwrapping:

mergeNodes

Merge a node with the previous node at the same depth.

Parameters

Collapse all

    Options for merging:

moveNodes

Move nodes from one location to another.

Parameters

Collapse all

    Options for moving:

liftNodes

Lift nodes upwards in the document tree.

Parameters

Collapse all

    Options for lifting nodes.

Text Operations

insertText

Insert text at the specified location or current selection.

Parameters

Collapse all

    The text to insert.

    Options for text insertion:

deleteText

Delete text in the document.

Parameters

Collapse all

    Options for deletion:

Selection Operations

select

Set the selection to a new value.

Parameters

Collapse all

    The target location.

    Options for selection:

setSelection

Set new properties on an active selection.

Parameters

Collapse all

    The selection properties to set.

DOM Operations

focus

Focus the editor.

Parameters

Collapse all

    Options for focusing:

History Operations

withoutNormalizing

Call a function, deferring normalization until after it completes.

Parameters

Collapse all

    The function to execute.

withMerging

Apply changes that will be merged into the previous history.

Parameters

Collapse all

    The function containing the changes.

withNewBatch

Apply changes starting a new batch in the history.

Parameters

Collapse all

    The function containing the changes.

addMark

Add a custom property to the leaf text nodes in the current selection.

Parameters

Collapse all

    The mark key to add.

    The value to set for the mark.

addMarks

Add multiple marks to the leaf text nodes in the current selection.

Parameters

Collapse all

    The marks to add.

    Options for adding marks:

removeMark

Remove a custom property from leaf text nodes in the current selection.

Parameters

Collapse all

    The mark key to remove.

removeMarks

Remove marks from text nodes.

Parameters

Collapse all

    The mark keys to remove.

    Options for removing marks:

toggleMark

Toggle a mark on the leaf text nodes in the current selection.

Parameters

Collapse all

    The mark key to toggle.

    The value to set when adding the mark.

    Options for toggling:

deleteBackward

Delete content backward from the current selection.

Parameters

Collapse all

    Options for deletion:

deleteForward

Delete content forward from the current selection.

Parameters

Collapse all

    Options for deletion:

deleteFragment

Delete the content of the current selection.

Parameters

Collapse all

    Options for deletion:

duplicateNodes

Duplicate nodes at a location.

Parameters

Collapse all

    Options for duplication:

insertBreak

Insert a block break at the current selection.

insertSoftBreak

Insert a soft break at the current selection.

normalize

Normalize any dirty objects in the editor.

Parameters

Collapse all

    Options for normalization:

redo

Redo to the next saved state.

undo

Undo to the previous saved state.

collapseSelection

Collapse the selection to a single point.

Parameters

Collapse all

    Options for collapsing:

moveSelection

Move the selection in a direction.

Parameters

Collapse all

    Options for moving:

setPoint

Set new properties on one of the selection's points.

Parameters

Collapse all

    The point properties to set.

    Options for setting point:

blur

Blur the editor.

deselect

Unset the selection.

withoutSaving

Apply changes without saving to history.

Parameters

Collapse all

    The function containing the changes.

withoutMerging

Apply changes without merging into previous history.

Parameters

Collapse all

    The function containing the changes.

History Operations

HistoryEditor

The HistoryEditor interface extends the base Editor interface to handle history operations.

Parameters

Collapse all

    The history of operations.

    Undo the last operation.

    Redo the last undone operation.