Plugin shortcuts map key combinations to plugin methods or explicit handlers. Plate compiles one immutable, ordered table during plugin setup. Each editable root installs one dispatcher for that table. This guide covers linked methods, custom handlers, overrides, priorities, and default shortcut ownership.
Each plugin owns a shortcuts object. At resolution time Plate namespaces every shortcut as ${plugin.name}.${shortcutName}.
Plate runs no shortcut for a key event that reports isComposing or carries keyCode 229, the code WebKit sends for the Enter that confirms an IME composition. Plugin onKeyDown handlers still receive the event.
When a shortcut has no handler, Plate looks for a same-named plugin method:
update.api.target: 'update' | 'api' to disambiguate.An explicit target must name an existing route. A custom handler owns dispatch
itself, so it cannot also set target.
Declare handlerless shortcuts after the method they link to. TypeScript validates
the capabilities already carried by that plugin descriptor, so the constructor
contribution with update or api comes before the
.extend({ shortcuts }) call. This real type dependency is why the example
uses a later stage. Custom handlers do not need a linked method.
| Field | Meaning |
|---|---|
keys | Key combination compiled by Plate's realm-aware matcher. Use a string like 'mod+b', or an array like ['mod+b', 'ctrl+b'] for several combinations. |
handler | Explicit callback receiving { editor, event }. |
target | Optional 'update' or 'api' disambiguation when both same-named routes exist. |
priority | Shortcut-local priority. Defaults to 0. |
null | Removes that named shortcut from the plugin. |
A single digit bound with mod matches that digit's key on a US layout,
whatever character Shift or the layout gives it. So mod+shift+0 fires on
Windows, where Shift makes the key report ), and mod+1 fires on a French
keyboard, where the key reports &. On Windows and Linux, where mod is
Control, a binding that adds alt matches only when the key types the digit.
Windows reads Control with Alt as AltGr, which types characters on many
layouts. To bind a key by its position whatever it types, write its code,
such as mod+alt+digit1.
Use a linked update method when the shortcut and plugin update method share a name.
import { definePlugin } from 'platejs/react';
export const SignaturePlugin = definePlugin('signature', {
update: ({ tx }) => ({
insertSignature: () => {
tx.text.insert(' - EditorRoot');
},
}),
})
.extend({
shortcuts: {
insertSignature: {
keys: 'mod+shift+s',
},
},
});import { definePlugin } from 'platejs/react';
export const SignaturePlugin = definePlugin('signature', {
update: ({ tx }) => ({
insertSignature: () => {
tx.text.insert(' - EditorRoot');
},
}),
})
.extend({
shortcuts: {
insertSignature: {
keys: 'mod+shift+s',
},
},
});Pressing Mod+Shift+S runs editor.update((tx) => tx.signature.insertSignature()).
When only the matching API method exists, Plate infers the API route.
import { DebugPlugin } from 'platejs';
import { definePlugin } from 'platejs/react';
export const InspectPlugin = definePlugin('inspect', {
api: ({ editor }) => ({
logText: () => {
editor
.plugin(DebugPlugin)
.api.info('Editor text', undefined, editor.read.text.string([]));
},
}),
})
.extend({
shortcuts: {
logText: {
keys: 'mod+alt+l',
},
},
});import { DebugPlugin } from 'platejs';
import { definePlugin } from 'platejs/react';
export const InspectPlugin = definePlugin('inspect', {
api: ({ editor }) => ({
logText: () => {
editor
.plugin(DebugPlugin)
.api.info('Editor text', undefined, editor.read.text.string([]));
},
}),
})
.extend({
shortcuts: {
logText: {
keys: 'mod+alt+l',
Pressing Mod+Alt+L calls
editor.plugin(InspectPlugin).api.logText().
If an update method and API method share a name, set target: 'update' or
target: 'api'. Plate never changes route silently when a second method is
added. Call plugin-owned APIs through editor.plugin(Plugin).api.
Use a handler when the shortcut needs the keyboard event, custom branching,
or work that should not live as a plugin API or update method. Do not set
target on a handler shortcut.
import { DebugPlugin } from 'platejs';
import { definePlugin } from 'platejs/react';
export const DraftPlugin = definePlugin('draft', {
shortcuts: {
saveDraft: {
keys: 'mod+s',
handler: ({ editor }) => {
const text = editor.read.text.string([]);
if (text.trim().length === 0) return false;
editor.plugin(DebugPlugin).api.info('Draft text', undefined, text);
return true;
},
},
},
});import { DebugPlugin } from 'platejs';
import { definePlugin } from 'platejs/react';
export const DraftPlugin = definePlugin('draft', {
shortcuts: {
saveDraft: {
keys: 'mod+s',
handler: ({ editor }) => {
const text = editor.read.text.string([]);
if (text.trim().length === 0) return false;
editor.plugin(DebugPlugin).api.info('Draft text', undefined, text);
| Handler returns | Behavior |
|---|---|
false | Not handled. Plate leaves the event alone and tries the next matching shortcut. |
| Anything else | Handled. Plate calls event.preventDefault() and event.stopPropagation(), so the key reaches no other key handler. |
Plate runs shortcuts on keydown. For a keyup action, use the plugin's
on.keyUp handler.
A handled shortcut always prevents the browser's own action, and the first
matching shortcut whose handler does not return false takes the key. So every
plugin that binds the key must let it through. To keep the browser's action on
every key press, set each of those shortcuts to null. To keep it only in some
places, wrap each plugin's handler with extend and return false there.
import { IndentPlugin } from 'platejs/react';
export const AppIndentPlugin = IndentPlugin.extend(({ plugin }) => ({
shortcuts: {
tab: {
keys: 'tab',
handler: (context) => {
const block = context.editor.read.nodes.block();
if (block?.[1][0] === 0) return false;
return plugin.shortcuts.tab?.handler?.(context);
},
},
},
}));import { IndentPlugin } from 'platejs/react';
export const AppIndentPlugin = IndentPlugin.extend(({ plugin }) => ({
shortcuts: {
tab: {
keys: 'tab',
handler: (context) => {
const block = context.editor.read.nodes.block();
if (block?.[1][0] === 0) return false;
return plugin.shortcuts.tab?.handler?.(context);
},
},
},
}));With IndentPlugin as the only Tab owner, Tab in the first block is left to
the browser, and Tab in any other block indents it. Other plugins bind Tab too,
such as ListPlugin, TablePlugin and CodeBlockPlugin, so wrap their Tab
shortcuts the same way when they are installed. A shortcut that links to a
plugin method has no handler to wrap, so its wrapper calls that method. A
shortcut cannot keep a target beside a handler. So when the linked shortcut
declares a target, such as CopilotPlugin's accept, set it to null and
declare the wrapper under a new name.
Configure a named shortcut to change its keys.
import { BoldPlugin } from 'platejs/react';
export const AppBoldPlugin = BoldPlugin.configure({
shortcuts: {
toggle: {
keys: 'mod+shift+b',
},
},
});import { BoldPlugin } from 'platejs/react';
export const AppBoldPlugin = BoldPlugin.configure({
shortcuts: {
toggle: {
keys: 'mod+shift+b',
},
},
});A configured shortcut keeps each field you leave out.
Set a shortcut to null to remove it.
import { ItalicPlugin } from 'platejs/react';
export const AppItalicPlugin = ItalicPlugin.configure({
shortcuts: {
toggle: null,
},
});import { ItalicPlugin } from 'platejs/react';
export const AppItalicPlugin = ItalicPlugin.configure({
shortcuts: {
toggle: null,
},
});The null value removes italic.toggle from the compiled shortcut set.
Read a plugin's keys from editor.plugin(plugin).shortcuts instead of writing
them again, so a rebound shortcut changes its label and a removed one shows
none. ariaKeyShortcuts from platejs/dom turns the keys into the value of the
aria-keyshortcuts attribute, such as Control+Shift+X, naming only combos
the editor's matcher matches on a US layout.
'use client';
import { ariaKeyShortcuts, usesAppleDOMHotkeys } from 'platejs/dom';
import { BoldPlugin, useEditor } from 'platejs/react';
import * as React from 'react';
export function BoldButton() {
const editor = useEditor();
const bold = editor.plugin(BoldPlugin);
const keys = bold.installed ? bold.shortcuts.toggle?.keys : undefined;
const [platform, setPlatform] = React.useState<'apple' | 'other'>();
React.useEffect(() => {
setPlatform(usesAppleDOMHotkeys(document) ? 'apple' : 'other');
}, []);
const shortcuts =
keys && platform ? ariaKeyShortcuts(keys, { platform }) : undefined;
return (
<button
type="button"
aria-keyshortcuts={shortcuts}
disabled={!bold.installed}
title={shortcuts ? `Bold (${shortcuts})` : 'Bold'}
onClick={() => bold.update.toggle()}
>
B
</button>
);
}'use client';
import { ariaKeyShortcuts, usesAppleDOMHotkeys } from 'platejs/dom';
import { BoldPlugin, useEditor } from 'platejs/react';
import * as React from 'react';
export function BoldButton() {
const editor = useEditor();
const bold = editor.plugin(BoldPlugin);
const keys = bold.installed ? bold.shortcuts.toggle?.keys : undefined;
const [platform, setPlatform] = React.useState<'apple' | 'other'>();
Read the shortcut only when installed is true, because reading the shortcuts
of a plugin the editor does not have throws. The server has no platform, so the
label waits for the first render in the browser. ariaKeyShortcuts returns
undefined when it can name no combo, such as mod+shift+0, whose character
depends on the keyboard layout. MarkToolbarButton
does this for every mark button and shows the keys as ⇧⌘X on Apple devices.
A plugin can declare multiple shortcut names. Keep each name aligned with the method it should call.
import { definePlugin } from 'platejs/react';
export const ReviewPlugin = definePlugin('review', {
update: ({ tx }) => ({
accept: () => tx.text.insert('Accepted'),
reject: () => tx.text.insert('Rejected'),
}),
})
.extend({
shortcuts: {
accept: {
keys: 'mod+alt+a',
},
reject: {
keys: 'mod+alt+r',
},
},
});import { definePlugin } from 'platejs/react';
export const ReviewPlugin = definePlugin('review', {
update: ({ tx }) => ({
accept: () => tx.text.insert('Accepted'),
reject: () => tx.text.insert('Rejected'),
}),
})
.extend({
shortcuts: {
accept: {
keys: 'mod+alt+a',
},
reject: {
keys: 'mod+alt+r',
},
},
This creates the compiled shortcut IDs review.accept and review.reject.
Shortcut priority defaults to 0. Set it on a shortcut when two handlers use
the same key combination and one should win.
import { definePlugin } from 'platejs/react';
export const PriorityPlugin = definePlugin('commandMenu', {
shortcuts: {
openCommandMenu: {
keys: 'mod+k',
priority: 200,
handler: ({ editor }) => {
editor.api.debug.info('Open command menu');
return true;
},
},
},
});import { definePlugin } from 'platejs/react';
export const PriorityPlugin = definePlugin('commandMenu', {
shortcuts: {
openCommandMenu: {
keys: 'mod+k',
priority: 200,
handler: ({ editor }) => {
editor.api.debug.info('Open command menu');
return true;
},
},
},
});Plate orders the compiled table by shortcut priority, plugin application order, then declaration order. The first handled route wins.
A digit and a symbol on the same key can match one press. On a French keyboard,
Control with the 6 key reports -, so it matches both mod+6 and mod+-. An
app that binds both gives the symbol's shortcut a higher priority.
An editor-wide command that belongs to no feature plugin goes in a small app plugin.
import { DebugPlugin } from 'platejs';
import { createEditor, definePlugin } from 'platejs/react';
const WordCountPlugin = definePlugin('wordCount', {
shortcuts: {
reportWordCount: {
keys: 'mod+shift+c',
handler: ({ editor }) => {
const words = editor.read.text
.string([])
.trim()
.split(/\s+/)
.filter(Boolean);
editor
.plugin(DebugPlugin)
.api.info('Word count', undefined, words.length);
return true;
},
},
},
});
export const editor = createEditor({ plugins: [WordCountPlugin] });import { DebugPlugin } from 'platejs';
import { createEditor, definePlugin } from 'platejs/react';
const WordCountPlugin = definePlugin('wordCount', {
shortcuts: {
reportWordCount: {
keys: 'mod+shift+c',
handler: ({ editor }) => {
const words = editor.read.text
.string([])
.trim()
.split(/\s+/)
.filter(Boolean);
editor
.plugin(DebugPlugin)
This creates the compiled shortcut ID wordCount.reportWordCount.
| Plugin | Shortcut name | Keys |
|---|---|---|
BoldPlugin | toggle | Mod+B |
ItalicPlugin | toggle | Mod+I |
UnderlinePlugin | toggle | Mod+U |
ParagraphPlugin | toggle | Mod+Alt+0, Mod+Shift+0 |
CopilotPlugin | accept | Tab |
CopilotPlugin | reject | Escape |
Other plugins often expose toggle, insert, or feature-specific transforms without default keys. Add shortcuts in your app when those commands should be keyboard-accessible.
type Shortcut = {
keys?: string | readonly string[];
priority?: number;
} & (
| {
handler: (context: {
editor: Editor;
event: KeyboardEvent;
}) => boolean | void;
target?: never;
}
| { handler?: never; target?: 'api' | 'update' }
);type Shortcut = {
keys?: string | readonly string[];
priority?: number;
} & (
| {
handler: (context: {
editor: Editor;
event: KeyboardEvent;
}) => boolean | void;
target?: never;
}
| { handler?: never; target?: 'api' | 'update' }
);target and handler are mutually exclusive.
Name shortcuts after plugin-specific transforms or API methods by default, and use handlers only when the keyboard event is part of the behavior.