charming icon indicating copy to clipboard operation
charming copied to clipboard

wip: map grid keyboard navigation with wsad, shortcut handling revamp

Open the6p4c opened this issue 2 years ago • 0 comments

:dog: this pr adds keyboard navigation to the map grid with the wsad keys (up, down, left, right) wsad was chosen over the arrow keys to avoid any potential confusion as a result of overriding native browser behaviour.

as part of this, the way shortcuts were previously implemented (keydown, copy and paste handlers on window in the root Charming component) has been refactored to allow components to listen for "global" shortcuts in a more local way. the shortcut context and ShortcutProvider provide a custom EventTarget which wraps and dispatches keydown, copy and paste events to components.

to handle a shortcut, components need only to:

const shortcuts = useShortcuts();
shortcuts.on("keydown", (e) => {
  if (e.is("x")) actionForXKey();
});

open questions:

  • does this hurt performance in any way?
    • mostly worried about the effect for each shortcut, and all movement on the map grid causing a navigation
    • we may want to debounce the actual navigation
  • are there any other shortcuts we can predict that might reveal that this api is bad?
  • did i break anything
  • who's a good girl?? who's a good girl??? ruffle ruffle

the6p4c avatar Oct 01 '23 07:10 the6p4c