Skip to content

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

ActionDefault
CopyCtrl/Cmd+C
PasteCtrl/Cmd+V
UndoCtrl/Cmd+Z
RedoCtrl/Cmd+Y or Ctrl/Cmd+Shift+Z
DeleteDelete
Rotate selectionR
Flip selection horizontalH
Flip selection verticalV

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>): void

Merges onto current bindings. Throws on conflict or bad format; previous bindings stay in effect.

match(event)

ts
match(event: KeyboardEvent): KeybindingAction | null

Returns the matching action, or null.

Errors

ErrorWhen
InvalidKeybindingErrorMalformed combo string (bad modifier, empty segment)
KeybindingConflictErrorTwo actions resolve to the same combo

Both throw synchronously from the constructor and patch().