Keybindings
Configurable keyboard shortcuts for PixelArtCanvas. See PixelArtCanvas.md.
ts
new Keybindings(patch?: Partial<KeybindingsMap>)patch is merged onto DEFAULT_KEYBINDINGS; omitted actions keep their defaults.
Keybinding format
A combo string of +-separated modifiers followed by a key: "mod+z", "mod+shift+z", "Delete".
mod: Ctrl on Windows/Linux, Cmd on macOS- Key is matched against
KeyboardEvent.key(case-insensitive) - Modifier matching is exact:
"mod+c"does not match Ctrl+Shift+C
ts
type ModifierToken = "mod" | "shift" | "alt";
type Keybinding =
| KeyToken
| `${ModifierToken}+${KeyToken}`
| `${ModifierToken}+${ModifierToken}+${KeyToken}`
| `${ModifierToken}+${ModifierToken}+${ModifierToken}+${KeyToken}`;
type KeybindingsMap = Record<KeybindingAction, Keybinding | Keybinding[]>;Defaults
| Action | Default |
|---|---|
| Copy | Ctrl/Cmd+C |
| Paste | Ctrl/Cmd+V |
| Undo | Ctrl/Cmd+Z |
| Redo | Ctrl/Cmd+Y or Ctrl/Cmd+Shift+Z |
| Delete | Delete |
| Rotate selection | R |
| Flip selection horizontal | H |
| Flip selection vertical | V |
IMPORTANT
rotate, flipHorizontal, flipVertical only apply in "select" mode with an active selection. Any action can be given an array of bindings.
API
bindings
ts
get bindings(): Readonly<KeybindingsMap>patch(patch)
ts
patch(patch: Partial<KeybindingsMap>): voidMerges onto current bindings. Throws on conflict or bad format; previous bindings stay in effect.
match(event)
ts
match(event: KeyboardEvent): KeybindingAction | nullReturns the matching action, or null.
Errors
| Error | When |
|---|---|
InvalidKeybindingError | Malformed combo string (bad modifier, empty segment) |
KeybindingConflictError | Two actions resolve to the same combo |
Both throw synchronously from the constructor and patch().