Basic Usage
Register shortcuts usingeditor.register.shortcutList():
Shortcut Configuration
IRegisterShortcut Interface
Modifier Keys
- mod (Recommended)
- ctrl
- meta
- Multiple Modifiers
Use This is the recommended approach for most shortcuts.
mod: true for cross-platform shortcuts:Available Keys
Use theKeyMap enum for key values:
See
/src/editor/dataset/enum/KeyMap.ts:1 in the source code for the complete list of available keys.Built-in Shortcuts
Canvas Editor includes built-in shortcuts for common text formatting:Text Formatting
Text Formatting
| Shortcut | Action | Source |
|---|---|---|
Mod+B | Bold | /src/editor/core/shortcut/keys/richtextKeys.ts:30 |
Mod+I | Italic | /src/editor/core/shortcut/keys/richtextKeys.ts:37 |
Mod+U | Underline | /src/editor/core/shortcut/keys/richtextKeys.ts:44 |
Ctrl+Shift+X | Strikethrough | /src/editor/core/shortcut/keys/richtextKeys.ts:8 |
Mod+] | Increase font size | /src/editor/core/shortcut/keys/richtextKeys.ts:16 |
Mod+[ | Decrease font size | /src/editor/core/shortcut/keys/richtextKeys.ts:22 |
Text Alignment
Text Alignment
| Shortcut | Action | Source |
|---|---|---|
Mod+L | Align left | /src/editor/core/shortcut/keys/richtextKeys.ts:67 |
Mod+E | Align center | /src/editor/core/shortcut/keys/richtextKeys.ts:73 |
Mod+R | Align right | /src/editor/core/shortcut/keys/richtextKeys.ts:79 |
Mod+J | Alignment | /src/editor/core/shortcut/keys/richtextKeys.ts:88 |
Mod+Shift+J | Justify | /src/editor/core/shortcut/keys/richtextKeys.ts:95 |
Subscript/Superscript
Subscript/Superscript
| Shortcut | Action | Source |
|---|---|---|
Mod+Shift+, (Mac) / Mod+Shift+> (Win) | Superscript | /src/editor/core/shortcut/keys/richtextKeys.ts:51 |
Mod+Shift+. (Mac) / Mod+Shift+< (Win) | Subscript | /src/editor/core/shortcut/keys/richtextKeys.ts:59 |
Real-World Examples
Global vs Editor Shortcuts
- Editor Shortcuts (Default)
- Global Shortcuts
By default, shortcuts only work when the editor is focused:Use this for most text editing shortcuts.
Disabling Shortcuts
Temporarily disable a shortcut without removing it:Disabling Built-in Shortcuts
To disable built-in shortcuts, use the editor options:Shortcuts registered later take precedence. The system processes shortcuts in the order they were registered, with the most recent taking priority.
Accessing Registered Shortcuts
Retrieve the list of registered shortcuts for debugging:Best Practices
Use mod for cross-platform
Always use
mod: true instead of ctrl or meta for shortcuts that should work on both platforms.Avoid browser conflicts
Don’t override common browser shortcuts like
Mod+T (new tab) or Mod+W (close tab).Document your shortcuts
Maintain a list of custom shortcuts for your users, especially if you’re building an application.
Test on multiple platforms
Always test shortcuts on both Mac and Windows to ensure consistent behavior.
Troubleshooting
Shortcut not triggering
Shortcut not triggering
- Check if the editor is focused (unless using
isGlobal: true) - Verify the key combination isn’t conflicting with browser shortcuts
- Ensure
disableis not set totrue - Check if another shortcut with the same combination was registered later
Global shortcut not working
Global shortcut not working
- Verify
isGlobal: trueis set - Check browser console for JavaScript errors
- Some browsers may block certain key combinations for security
Cross-platform issues
Cross-platform issues
- Use
mod: trueinstead ofctrlormeta - Test on both macOS and Windows
- Consider platform-specific keys for special cases (see
/src/editor/core/shortcut/keys/richtextKeys.ts:51)
Next Steps
Context Menus
Add custom context menu items
Commands API
Explore available commands
Plugin System
Create custom plugins
Events
Listen to editor events