Skip to content

Plugin: ShortcutContext

Description

The ShortcutContext API lets you store and manage keyboard shortcuts in a given context.

Each ShortcutContext object stores and manages its own set of keyboard shortcuts.

Methods

addShortcut

Source code

shortcutContext.addShortcut(options)

Add a keyboard shortcut to this context.

ParamTypeDefaultDescription
optionsobjectThe shortcut’s options
options.keysArray<Array<string>>Names of the shortcut’s keys, (coming from KeyboardEvent.key), in lowercase or uppercase, unified across browsers
options.callbackfunctionThe shortcut’s action
options.groupobjectA group of shortcuts to which the shortcut belongs
[options.runOnlyIf]objectoptional A condition on which the shortcut’s action runs
[options.stopPropagation]objectfalseoptional If set to true: stops the event’s propagation
[options.captureCtrl]objectfalseoptional If set to true: captures the state of the Control/Meta modifier key
[options.preventDefault]objecttrueoptional If set to true: prevents the default behavior
[options.position]object’after’optional The order in which the shortcut’s action runs: 'before' or 'after' the relativeToGroup group of actions
[options.relativeToGroup]objectoptional The name of a group of actions, used to determine an action’s position
[options.forwardToContext]objectoptional The context object where the event will be forwarded to.

addShortcuts

Source code

shortcutContext.addShortcuts(shortcuts, [options])

Add multiple keyboard shortcuts to this context.

ParamTypeDefaultDescription
shortcutsArray<object>List of shortcuts to add to this shortcut context
[options]objectoptional A shortcut’s options
[options.callback]functionoptional A shortcut’s action
[options.group]objectoptional A group of shortcuts to which a shortcut belongs
[options.runOnlyIf]objectoptional A condition on which a shortcut’s action runs
[options.stopPropagation]objectfalseoptional If set to true: stops the event’s propagation
[options.preventDefault]objecttrueoptional If set to true: prevents the default behavior
[options.position]object’after’optional The order in which a shortcut’s action runs: 'before' or 'after' a relativeToGroup group of actions
[options.relativeToGroup]objectoptional The name of a group of actions, used to determine an action’s position
[options.forwardToContext]objectoptional The context object where the event will be forwarded to.

getShortcuts

Source code

shortcutContext.getShortcuts(keys) ⇒ Array

Get a shortcut’s details.

ParamTypeDescription
keysArray<string>Names of the shortcut’s keys, (coming from KeyboardEvent.key), in lowercase or uppercase, unified across browsers

hasShortcut

Source code

shortcutContext.hasShortcut(keys) ⇒ boolean

Check if a shortcut exists in this context.

ParamTypeDescription
keysArray<string>Names of the shortcut’s keys, (coming from KeyboardEvent.key), in lowercase or uppercase, unified across browsers

removeShortcutsByGroup

Source code

shortcutContext.removeShortcutsByGroup(group)

Remove a group of shortcuts from this context.

ParamTypeDescription
groupstringThe name of the group of shortcuts

removeShortcutsByKeys

Source code

shortcutContext.removeShortcutsByKeys(keys)

Remove a shortcut from this context.

ParamTypeDescription
keysArray<string>Names of the shortcut’s keys, (coming from KeyboardEvent.key), in lowercase or uppercase, unified across browsers