Skip to main content

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
Example

insertContent()

Insert content at the current position.
Content
required
The content to insert.
InsertContentOptions
Example

insertContentAt()

Insert content at a specific position.
number | Range
required
The position or range where to insert content.
Content
required
The content to insert.
Example

clearContent()

Clear the entire document.
boolean
default:"true"
Whether to emit an update event.
Example

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.
Example

blur()

Remove focus from the editor.
Example

setTextSelection()

Set the text selection.
number | Range
required
The position or range to select.
Example

selectAll()

Select the entire document.
Example

selectParentNode()

Select the parent node.
Example

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.
Example

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.
Example

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.
Example

unsetAllMarks()

Remove all marks from the selection.
Example

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.
Example

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.
Example

deleteNode()

Delete a node.
string | NodeType
required
The node type or name to delete.
Example

deleteCurrentNode()

Delete the currently selected node.
Example

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').
Example

sinkListItem()

Sink a list item (increase indent).
string | NodeType
required
The list item type.
Example

liftListItem()

Lift a list item (decrease indent).
string | NodeType
required
The list item type.
Example

splitListItem()

Split a list item at the current position.
string | NodeType
required
The list item type.
Example

Text Transformation Commands

deleteSelection()

Delete the current selection.
Example

deleteRange()

Delete content in a range.
Range
required
The range to delete.
Example

enter()

Trigger enter key behavior.
Example

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.
Example

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.
Example

Utility Commands

scrollIntoView()

Scroll the current selection into view.
Example

setMeta()

Set transaction metadata.
string
required
The metadata key.
any
required
The metadata value.
Example

Creating Custom Commands

You can create custom commands in extensions:

Command Return Values

All commands return a boolean:
  • true - Command executed successfully
  • false - Command could not be executed (e.g., invalid state, not applicable)