Commands
A command is a function that may modify the editor state. ProseKit exposes them in two flavors: low-level ProseMirror commands, and high-level "command actions" that the editor wraps around them.
Two ways to call a command
Section titled “Two ways to call a command”The action form is what you'll use 95% of the time. It's typed (you get autocomplete for every command your extensions registered) and it exposes .canExec() for "is this currently applicable?":
Built-in commands
Section titled “Built-in commands”Most extensions ship a command pair like toggleBold / setHeading on editor.commands.
Useful low-level commands also live on prosekit/core:
| Command | Notes |
|---|---|
addMark | Apply a mark to a range. |
removeMark | Remove a mark from a range. |
toggleMark | Toggle a mark on the current selection. |
unsetMark | Drop stored marks (affects newly typed text). |
expandMark | Expand the selection to cover an existing mark. |
setBlockType | Change the current block to a specific type. |
unsetBlockType | Reset the current block to the default. |
toggleNode | Toggle the current block between two types. |
toggleWrap | Toggle a wrapping node (e.g. blockquote). |
wrap | Wrap the selection in a node. |
insertNode | Insert a node at the selection. |
removeNode | Remove the nearest node of a type. |
setNodeAttrs | Update attributes on the current node. |
selectAll | Move selection to the whole document. |
selectBlock | Select the current block node. |
insertDefaultBlock | Insert the default block (usually a paragraph). |
See the prosekit/core reference for full signatures.
Defining your own command
Section titled “Defining your own command”Use defineCommands (note the plural; the singular defineCommand does not exist). The keys become the action names; each value is a function that returns a ProseMirror Command.
Later, you can call editor.commands.insertHello() and editor.commands.insertNTimes('Hey', 3), with their argument types inferred from the function signatures.
Keymaps
Section titled “Keymaps”defineKeymap maps a key string to a Command. See Keyboard Shortcuts for the full key syntax (Mod, Shift, Alt, Meta, etc.).
Every framework integration also exposes a useKeymap hook for binding keys conditionally (see the React page).