Overview
CommandShortcutEvent defines the implementation of shortcut events based on keyboard commands (modifier keys + regular keys). These events handle common editor operations like copy, paste, undo, redo, and navigation.
Constructor
Parameters
The unique key for the shortcut event. Usually uses the description as the key.Example:
'undo', 'copy the selected content'The string representation for the keyboard keys. Supports multiple key combinations separated by commas.Modifier key mapping:
ctrl- Ctrl keymeta- Command (macOS) or Control (Windows)alt- Alt keyshift- Shift keycmd- Alias for metawin- Alias for meta
'ctrl+c'- Single combination'ctrl+y,ctrl+shift+z'- Multiple combinations
The handler function to execute when the shortcut is triggered.Type signature:Returns
KeyEventResult.handled if processed, or KeyEventResult.ignored if not.Callback function that returns a localized description of the command. Used for displaying shortcuts in UI.Example:
() => AppFlowyEditorL10n.current.cmdUndoPlatform-specific command for Windows. Overrides
command on Windows.Example: 'ctrl+y'Platform-specific command for macOS. Overrides
command on macOS.Example: 'cmd+z'Platform-specific command for Linux. Overrides
command on Linux.Properties
key
command
handler
keybindings
description
getDescription is not provided.
Methods
updateCommand()
command- Default command for all platformswindowsCommand- Windows-specific overridemacOSCommand- macOS-specific overridelinuxCommand- Linux-specific override
clearCommand()
updateCommand().
canRespondToRawKeyEvent()
event- The key event to check
true if this shortcut matches the event.
execute()
editorState- The current editor state
KeyEventResult.handled or KeyEventResult.ignored.
copyWith()
Examples
Copy Command
Undo Command
Redo Command
Multiple key combinations for the same action:Platform-Specific Commands
Updating Commands Dynamically
Usage
To use command shortcut events in your editor:Command String Format
The command string uses a specific format:- Modifiers:
ctrl,meta,cmd,win,alt,shift - Separator:
+or-between modifiers and keys - Multiple combinations: Use
,to separate different key combinations - Case insensitive: Commands are parsed in lowercase
'ctrl+c'- Ctrl + C'cmd+shift+z'- Command + Shift + Z (macOS)'ctrl+y,ctrl+shift+z'- Either Ctrl+Y OR Ctrl+Shift+Z'meta+enter'- Meta + Enter (Command on macOS, Control on Windows)
Key Event Results
Handlers should return:KeyEventResult.handled- Event was processed, prevent further handlingKeyEventResult.ignored- Event was not processed, allow other handlers
See Also
- CharacterShortcutEvent - For character-based shortcuts
- Key Mapping - Key code mapping utilities
- Shortcut Events Guide - Custom keyboard shortcuts