insertDefaultBlock command
The insertDefaultBlock command inserts the schema's default content block type at a given position. The block type is determined automatically using defaultBlockAt(), so the schema decides what fits at the insertion point.
This is useful for inserting context-aware empty blocks, for example, inserting a paragraph inside a document or a blockquote — without hardcoding the node type.
The command returns false when no valid default block can be inserted at the position (e.g., when the position is inside a textblock). It does not silently reposition.
Parameters
options: InsertDefaultBlockOptions
pos: number | ResolvedPos– Position to insert the block at. Accepts a numeric offset or a resolved ProseMirror position. Defaults to the current caret position.attrs: Record<string, any>– Attributes to apply to the inserted node. Only keys defined in the node type'sspec.attrsare kept; unknown attributes are filtered out.content: Content | ProseMirrorNode | Fragment– Content to insert into the block. Accepts plain text, an HTML string, or a ProseMirror node/fragment.updateSelection: boolean– Whether to move the selection to the newly inserted block. Defaults totrue.
Use the insertDefaultBlock command
// Insert at the current selection position
editor.commands.insertDefaultBlock()
// Insert at a specific position
editor.commands.insertDefaultBlock({ pos: 0 })
// Insert with text content
editor.commands.insertDefaultBlock({ pos: 0, content: 'Hello' })
// Insert with HTML content
editor.commands.insertDefaultBlock({ pos: 0, content: '<strong>bold</strong>' })
// Insert a heading (when heading is the default block at that position)
editor.commands.insertDefaultBlock({ pos: 0, attrs: { level: 2 }, content: 'Title' })
// Insert without updating the selection
editor.commands.insertDefaultBlock({ pos: 0, content: 'Hello', updateSelection: false })