• Nathan Friend's avatar
    Abstract keyboard shortcut bindings · 191f857b
    Nathan Friend authored
    This commit updates the way in which we bind key sequences to functions
    when implementing keyboard shortcuts.
    
    Before this commit, developers would directly bind a key sequence to a
    handler:
    
    ```js
    Mousetrap.bind('p b', handler);
    ```
    
    After this commit, developers will instead define a new "command" in
    `~/behaviors/shortcuts/keybindings.js` and bind to the result of
    `keysFor(command)`:
    
    ```js
    import { keysFor, TOGGLE_PERFORMANCE_BAR }
    from '~/behaviors/shortcuts/keybindings.js';
    
    Mousetrap.bind(keysFor(TOGGLE_PERFORMANCE_BAR), handler);
    ```
    
    `keybindings.js` handles returning the appropriate key sequence for
    the command (or it returns `[]` if the command is disabled).
    191f857b
keybindings_spec.js 1.82 KB