Skip to content

Commands

Unofficial

Manager for registering, finding, and executing commands.

Import:

import type { Commands } from '@obsidian-typings/obsidian-catalyst-latest';

Signature:

export interface Commands extends Events

Extends: Events

Constructor

new Commands(app: App)

Constructor.

To get the constructor instance, use getCommandsConstructor from obsidian-typings/implementations.

Properties

Property Type Description
_ Record<string, EventsEntry[]> Internal storage of registered event handlers by event name.
(Inherited from Events)
app App Reference to the obsidian#App.
commands CommandsCommandsRecord Commands *without* editor callback, will always be available in the command palette.
editorCommands CommandsEditorCommandsRecord Commands *with* editor callback, will only be available when editor is active and callback returns true.

Methods

Method Returns Description
addCommand(command) void Add a command to the command registry.
executeCommand(command, event?) boolean Execute a command by reference.
executeCommandById(commandId, event?) boolean Execute a command by ID.
findCommand(commandId) Command | undefined Find a command by ID.
listCommands() Command[] Lists **all** commands, both with and without editor callback.
off(name, callback) void Remove an event listener.
(Inherited from Events)
offref(ref) void Remove an event listener by reference.
(Inherited from Events)
on(name, callback, ctx?) EventRef Add an event listener.
(Inherited from Events)
removeCommand(commandId) void Remove a command from the command registry.
trigger(name, data?) void Trigger an event, executing all the listeners in order even if some of them throw an error.
(Inherited from Events)
tryTrigger(evt, args) void Try to trigger an event, executing all the listeners in order even if some of them throw an error.
(Inherited from Events)

Links to this page: