KeyBindingManager

Description

Manages the mapping of keyboard inputs to commands.

Functions Summary

Functions

_handleCommandRegistered

Adds default key bindings when commands are registered to CommandManager

event $.Event
jQuery event
command Command
Newly registered command
Public API

_handleKey

Process the keybinding for the current key.

A string
key-description string.
Returns: boolean
true if the key was processed, false otherwise
Public API

_handleKeyEvent

Handles a given keydown event, checking global hooks first before deciding to handle it ourselves.

The Event
keydown event to handle.

_translateKeyboardEvent

Takes a keyboard event and translates it into a key in a key map

Public API

addBinding

Add one or more key bindings to a particular Command.

command non-nullable string, Command
- A command ID or command object
| nullable ({key: string, displayKey: string
Array.<{key: string, displayKey: string, platform: string}>)} keyBindings a single key binding or an array of keybindings. Example: "Shift-Cmd-F". Mac and Win key equivalents are automatically mapped to each other. Use displayKey property to display a different string (e.g. "CMD+" instead of "CMD=").
platform nullable string
- the target OS of the keyBindings either "mac", "win" or "linux". If undefined, all platforms not explicitly defined will use the key binding.
Returns: {key: string,displayKey:String},Array.<{key: string,displayKey:String}>
Returns record(s) for valid key binding(s)
Public API

addGlobalKeydownHook

Adds a global keydown hook that gets first crack at keydown events before standard keybindings do. This is intended for use by modal or semi-modal UI elements like dialogs or the code hint list that should execute before normal command bindings are run.

The hook is passed one parameter, the original keyboard event. If the hook handles the event (or wants to block other global hooks from handling the event), it should return true. Note that this will only stop other global hooks and KeyBindingManager from handling the event; to prevent further event propagation, you will need to call stopPropagation(), stopImmediatePropagation(), and/or preventDefault() as usual.

Multiple keydown hooks can be registered, and are executed in order, most-recently-added first.

(We have to have a special API for this because (1) handlers are normally called in least-recently-added order, and we want most-recently-added; (2) native DOM events don't have a way for us to find out if stopImmediatePropagation()/stopPropagation() has been called on the event, so we have to have some other way for one of the hooks to indicate that it wants to block the other hooks from running.)

hook function(Event): boolean
The global hook to add.
Public API

formatKeyDescriptor

Convert normalized key representation to display appropriate for platform.

descriptor non-nullable string
Normalized key descriptor.
Returns: !string
Display/Operating system appropriate string
Public API

getKeyBindings

Retrieve key bindings currently associated with a command

command non-nullable string, Command
- A command ID or command object
Returns: !Array.<{{key: string,displayKey: string}}>
An array of associated key bindings.
Public API

getKeymap

Returns a copy of the keymap

returns
{!Object.<string, {commandID: string, key: string, displayKey: string}>}

normalizeKeyDescriptorString

normalizes the incoming key descriptor so the modifier keys are always specified in the correct order

The string
string for a key descriptor, can be in any order, the result will be Ctrl-Alt-Shift-
Returns: string
The normalized key descriptor or null if the descriptor invalid
Public API

removeBinding

Remove a key binding from _keymap

key non-nullable string
- a key-description string that may or may not be normalized.
platform nullable string
- OS from which to remove the binding (all platforms if unspecified)
Public API

removeGlobalKeydownHook

Removes a global keydown hook added by addGlobalKeydownHook. Does not need to be the most recently added hook.

hook function(Event): boolean
The global hook to remove.
Public API

setEnabled

Enable or disable key bindings. Clients such as dialogs may wish to disable global key bindings temporarily.

A string
key-description string.
Returns: boolean
true if the key was processed, false otherwise