Command System
Tiptap provides a command system that allows you to manipulate the editor content. Commands can be executed individually, chained together, or checked for availability.Single Commands
Execute commands directly:Chained Commands
Chain multiple commands and execute them at once:Can Commands
Check if a command can be executed without running it:Content Commands
setContent()
Replace the whole document with new content.Content
required
The new content (HTML, JSON, or ProseMirror node).
SetContentOptions
insertContent()
Insert content at the current position.Content
required
The content to insert.
InsertContentOptions
insertContentAt()
Insert content at a specific position.number | Range
required
The position or range where to insert content.
Content
required
The content to insert.
clearContent()
Clear the entire document.boolean
default:"true"
Whether to emit an update event.
Selection Commands
focus()
Focus the editor at a specific position.FocusPosition
Where to focus:
'start', 'end', 'all', true, false, or a number.boolean
default:"true"
Whether to scroll the focused position into view.
blur()
Remove focus from the editor.setTextSelection()
Set the text selection.number | Range
required
The position or range to select.
selectAll()
Select the entire document.selectParentNode()
Select the parent node.Mark Commands
setMark()
Apply a mark to the selection.string | MarkType
required
The mark type or name.
Record<string, any>
Attributes to apply to the mark.
toggleMark()
Toggle a mark on and off.string | MarkType
required
The mark type or name.
Record<string, any>
Attributes of the mark.
boolean
default:"false"
Removes the mark even across the current selection.
unsetMark()
Remove a mark from the selection.string | MarkType
required
The mark type or name.
boolean
default:"false"
Removes the mark even across the current selection.
unsetAllMarks()
Remove all marks from the selection.Node Commands
setNode()
Change the type of a node.string | NodeType
required
The node type or name.
Record<string, any>
Attributes to set on the node.
toggleNode()
Toggle a node with another node.string | NodeType
required
The node type or name to toggle.
string | NodeType
required
The node type to toggle with.
Record<string, any>
Attributes for the node.
deleteNode()
Delete a node.string | NodeType
required
The node type or name to delete.
deleteCurrentNode()
Delete the currently selected node.List Commands
toggleList()
Toggle between a list and normal paragraphs.string | NodeType
required
The list type (e.g.,
'bulletList', 'orderedList').string | NodeType
required
The list item type (usually
'listItem').sinkListItem()
Sink a list item (increase indent).string | NodeType
required
The list item type.
liftListItem()
Lift a list item (decrease indent).string | NodeType
required
The list item type.
splitListItem()
Split a list item at the current position.string | NodeType
required
The list item type.
Text Transformation Commands
deleteSelection()
Delete the current selection.deleteRange()
Delete content in a range.Range
required
The range to delete.
enter()
Trigger enter key behavior.Attribute Commands
updateAttributes()
Update attributes of a node or mark.string | NodeType | MarkType
required
The node or mark type or name.
Record<string, any>
required
The attributes to update.
resetAttributes()
Reset node or mark attributes to defaults.string | NodeType | MarkType
required
The node or mark type or name.
string | string[]
required
The attribute names to reset.
Utility Commands
scrollIntoView()
Scroll the current selection into view.setMeta()
Set transaction metadata.string
required
The metadata key.
any
required
The metadata value.
Creating Custom Commands
You can create custom commands in extensions:Command Return Values
All commands return a boolean:true- Command executed successfullyfalse- Command could not be executed (e.g., invalid state, not applicable)