Skip to content

feat: configurable keyboard shortcuts via keyboardShortcuts option#19

Merged
dpecos merged 1 commit into
masterfrom
feat/issue-8-configurable-keyboard-shortcuts
Apr 16, 2026
Merged

feat: configurable keyboard shortcuts via keyboardShortcuts option#19
dpecos merged 1 commit into
masterfrom
feat/issue-8-configurable-keyboard-shortcuts

Conversation

@dpecos
Copy link
Copy Markdown
Contributor

@dpecos dpecos commented Apr 16, 2026

Summary

  • Adds a keyboardShortcuts option to createSlideshow() for remapping, extending, or disabling any key binding
  • Rewrites Keyboard class to use KeyboardEvent.key + keydown (replaces the deprecated keyCode / keypress approach)
  • 19 new tests covering defaults, overrides, disabling, arrays of keys, and activate/deactivate

API

mdeck.createSlideshow({
  keyboardShortcuts: {
    // Replace default keys for an action
    gotoNextSlide: ['ArrowRight', 'ArrowDown', 'j', ' '],
    // Single key as a string
    togglePresenterMode: 'p',
    // Disable a default binding entirely
    toggleFullscreen: null,
    // Add a completely new action binding
    customAction: 'x',
  }
});

Behaviour

Config value Effect
string Replaces default keys for that action
string[] Replaces default keys with the array
null Disables that action entirely
omitted Default keys are kept unchanged

Implementation notes

  • DEFAULT_SHORTCUTS is exported so callers can inspect or extend it
  • All key matching uses KeyboardEvent.key (e.g. 'ArrowRight', 'j', ' ')
  • Single-character keys are normalised to lowercase for case-insensitive matching
  • Shift+Space → previous slide is preserved as a special case (not in the keymap, so it cannot be accidentally overridden via the config)
  • Digit accumulator (0–9 then Enter → gotoSlideNumber) is also a special case outside the keymap

Closes #8

Adds a keyboardShortcuts option to createSlideshow() that lets users
remap, extend, or disable any key binding without forking the library.

- SlideshowOptions gains a keyboardShortcuts field (KeyboardShortcutsConfig)
- Keyboard class now accepts an optional shortcuts config, merges it over
  DEFAULT_SHORTCUTS, and builds an inverted key→action map
- Unified onto keydown + event.key (replaces the old keyCode/keypress mix)
- Setting a shortcut to null disables the default binding for that action
- Setting it to a string or string[] replaces the default binding
- Unmentioned actions keep their defaults
- DefaultController forwards options.keyboardShortcuts to Keyboard

Closes #8
@dpecos dpecos merged commit 353b273 into master Apr 16, 2026
4 checks passed
@dpecos dpecos deleted the feat/issue-8-configurable-keyboard-shortcuts branch April 16, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: configurable keyboard shortcuts

1 participant