Keyboard Shortcuts API

Keyboard Shortcuts

Keyboard shortcuts can be applied to views only. To work properly, the view must be in focus.
Shortcuts are bounds to actions (see link).
For using keyboard shortcuts action should provide two methods:

handler - required
isEnabled - optional, returns true value by default

If you want get view selection, you implement the method “getSelection” for the current view.

Defining Shortcuts

To define new shortcuts, add a configuration as described in the following example
into your avid array exported from your plugin.
Example for keyboard shortcuts for two views, which are bound to the action - action-name:

    {
        name: 'action-name',
        provides: ['actions'],
        create: () => ({
            id: 'action-name',
            isEnabled({ event, component, selection }) {
                return true;
            },
            handler({ event, component, selection }) {
                component.someMethod({ event, selection });
            }
        }),
    },
    {
        name: 'shortcuts-name',
        provides: ['hotkeyBindings'],
        create: () => ({
            config: [{
                actionId: 'action-name'
                keys: 'ctrl+alt+/',
                views: ['avid-nux-mock-hotkeys'],
                filter: (viewType) => {
                    return viewType === 'some-view-type-name'
                }
            }, {
                actionId: 'action-name'
                keys: 'alt+m',
                views: ['avid-nux-mock-hotkeys-2'],
             }]
        }),
    },
        

Action Create Function Description

    create: () => ({
        id: 'action-name',
        
        /**
         * Checks if current keyboard shortcut is enabled.
         * @param {Object} event Browser event
         * @param {Object} component View publicScope
         * @param {Object} selection Data from view getSelection method
         * @return {boolean}
         */
        isEnabled({ event, component, selection }) {
            return true;
        },
        
        /**
         * Keyboard shortcuts handler.
         * @param event Browser event
         * @param component View publicScope
         * @param selection Data from view getSelection method
         */
        handler({ event, component, selection }) {
            component.someMethod({ event, selection });
        }
    }),

Keyboard Shortcuts Object Description

  • name unique shortcut name
  • provides processor name, must be the same as shown in the example
  • create function returns object data
    • config array of keyboard shortcuts configuration
      • actionId action id
      • keys string with keyboard shortcuts (allowed symbols see below)
      • views array of view names
      • filter (optional) function, will be called for filtering views, receives one argument - viewType

If filter is defined, the views property is not required.

Allowed Symbols for “keys” Property

    up down let right enter meta ctrl shift alt esc space backspace tab
    pageup pagedown del ins home end capslock
    * + - . / ; = , [ ] \ ' `
    ! @ # $ % ^ & ( ) _ - { } < > ? | : " 
    0 1 2 3 4 5 6 7 8 9
    A-Z a-z

Exapmples: 
    'ctrl+up', 'alt+9', 'ctrl+up+del', 'ctrl+h', 'ctrl+home', 'd', 'D', '#'

Invalid example: 
    'ctrl+D', 'ctrl+shift+D', 'alt+@', 'shift+alt+@'   

Important: Don’t use space at the start and end of the “keys” string value.
Don’t use special symbols, which are obtained by the shift key
in any keyboard shortcuts combination. Use them alone as shown in the example above.