An object which manages a collection of commands.

Notes

A command registry can be used to populate a variety of action-based widgets, such as command palettes, menus, and toolbars.

Hierarchy

  • CommandRegistry

Constructors

Properties

_commandChanged: Signal<CommandRegistry, ICommandChangedArgs> = ...
_commandExecuted: Signal<CommandRegistry, ICommandExecutedArgs> = ...
_commands: Map<string, ICommand> = ...
_exactKeyMatch: null | IKeyBinding = null
_keyBindingChanged: Signal<CommandRegistry, IKeyBindingChangedArgs> = ...
_keyBindings: IKeyBinding[] = []
_keydownEvents: KeyboardEvent[] = []
_keystrokes: string[] = []
_replaying: boolean = false
_timerID: number = 0

Accessors

Methods

  • Add a key binding to the registry.

    Returns

    A disposable which removes the added key binding.

    Notes

    If multiple key bindings are registered for the same sequence, the binding with the highest selector specificity is executed first. A tie is broken by using the most recently added key binding.

    Ambiguous key bindings are resolved with a timeout. As an example, suppose two key bindings are registered: one with the key sequence ['Ctrl D'], and another with ['Ctrl D', 'Ctrl W']. If the user presses Ctrl D, the first binding cannot be immediately executed since the user may intend to complete the chord with Ctrl W. For such cases, a timer is used to allow the chord to be completed. If the chord is not completed before the timeout, the first binding is executed.

    Parameters

    Returns IDisposable

  • Execute a specific command.

    Returns

    A promise which resolves with the result of the command.

    Notes

    The promise will reject if the command throws an exception, or if the command is not registered.

    Parameters

    • id: string

      The id of the command of interest.

    • args: ReadonlyPartialJSONObject = JSONExt.emptyObject

      The arguments for the command.

    Returns Promise<any>

  • Test whether a specific command is registered.

    Returns

    true if the command is registered, false otherwise.

    Parameters

    • id: string

      The id of the command of interest.

    Returns boolean

  • Get the icon renderer for a specific command.

    DEPRECATED: if set to a string value, the .icon field will function as an alias for the .iconClass field, for backwards compatibility. In the future when this is removed, the default return type will become undefined.

    Returns

    The icon renderer for the command or undefined.

    Parameters

    • id: string

      The id of the command of interest.

    • args: ReadonlyPartialJSONObject = JSONExt.emptyObject

      The arguments for the command.

    Returns undefined | IRenderer

  • Test whether a specific command is toggleable.

    Returns

    A boolean indicating whether the command is toggleable, or false if the command is not registered.

    Parameters

    • id: string

      The id of the command of interest.

    • args: ReadonlyJSONObject = JSONExt.emptyObject

      The arguments for the command.

    Returns boolean

  • List the ids of the registered commands.

    Returns

    A new array of the registered command ids.

    Returns string[]

  • Notify listeners that the state of a command has changed.

    Throws

    An error if the given id is not registered.

    Notes

    This method should be called by the command author whenever the application state changes such that the results of the command metadata functions may have changed.

    This will cause the commandChanged signal to be emitted.

    Parameters

    • Optional id: string

      The id of the command which has changed. If more than one command has changed, this argument should be omitted.

    Returns void

  • Process a 'keydown' event and invoke a matching key binding.

    Parameters

    • event: KeyboardEvent

      The event object for a 'keydown' event.

      Notes

      This should be called in response to a 'keydown' event in order to invoke the command for the best matching key binding.

      The registry does not install its own listener for 'keydown' events. This allows the application full control over the nodes and phase for which the registry processes 'keydown' events.

      When the keydown event is processed, if the event target or any of its ancestor nodes has a data-lm-suppress-shortcuts attribute, its keydown events will not invoke commands.

    Returns void

Generated using TypeDoc