CustomAction>= v1.9.0
CustomAction:
{}Custom actions allow you to add your own functionality to the editor. Unlike BuiltInAction, custom actions must provide a handler
function.
If capabilities is omitted, a custom action counts as document.change, so it
can’t run in view mode. This keeps existing integrations working as before. To let
a custom action run in view mode, give it only capabilities that view mode allows,
such as external.open.
Example
Section titled “Example”
// Add a custom action with keyboard shortcuteditor.setActions([ { id: 'custom.insert-signature', label: 'Insert Signature', shortcuts: ['Mod+Shift+S'], handler: () => { editor.insertTextAtCursor('\n\nBest regards,\nJohn Doe'); }, },]);
// Add a custom action with custom iconeditor.setActions([ { id: 'custom.save', label: 'Save Document', icon: 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiPi4uLjwvc3ZnPg==', handler: async () => { const doc = await editor.currentDocument().saveDocument(); await fetch('/api/save', { method: 'POST', }); }, },]);
// Add a conditional action (disabled when no cursor/selection)editor.setActions([ { id: 'custom.insert-date', label: "Insert Today's Date", isEnabled: () => editor.hasActiveCursor(), handler: () => { editor.insertTextAtCursor(date); }, },]);
// Allow a read-only custom action to run in view modeeditor.setActions([ { id: 'custom.open-help', label: 'Open Help', capabilities: ['external.open'], handler: () => { window.open('/help', '_blank'); }, },]);BuiltInActionfor built-in actions with default implementations.ToolbarActionItemfor adding custom actions to the toolbar.
Properties
Section titled “Properties”id:
string
Unique identifier for this action (must not be a BuiltInActionId)
label:
string
Text shown for the action in the command palette and on
ToolbarActionItem buttons. The editor doesn’t translate it and shows the same
text whatever the locale.
description?
Section titled “description?”
optionaldescription:string
capabilities?
Section titled “capabilities?”
optionalcapabilities: readonlyActionCapability[]
What kind of change the action makes, which decides the editor modes it can run
in. Defaults to document.change. setActions() throws on values that are not
an ActionCapability.
shortcuts?
Section titled “shortcuts?”
optionalshortcuts:string[]
Keyboard shortcuts for the action. Use “Mod” as the primary modifier key - it will be automatically resolved to:
- “Ctrl” on Windows/Linux
- ”⌘” (Command) on Mac
Examples:
- “Mod+B” becomes “Ctrl+B” on Windows, “⌘B” on Mac
- “Mod+Shift+P” becomes “Ctrl+Shift+P” on Windows, ”⌘⇧P” on Mac
optionalicon:string
Icon as data URI (e.g., data:image/svg+xml;base64,… or data:image/png;base64,…). Only data:image/ URIs are allowed for security.
isEnabled()?
Section titled “isEnabled()?”
optionalisEnabled: () =>boolean
Optional function to determine if this action should be enabled
Returns
Section titled “Returns”handler()
Section titled “handler()”Handler function that executes when the action is triggered (required for custom actions)
Parameters
Section titled “Parameters”…any[]