Command
API reference uses a reviewed source snapshot. Source links open the published source; unverified line locations are omitted.
Defined in: command.svelte.ts:29
Properties
Section titled “Properties”activationEvent?
Section titled “activationEvent?”
optionalactivationEvent?:string
Defined in: command.svelte.ts:71
Activation event used to wake deferred command implementations.
argumentSchema?
Section titled “argumentSchema?”
optionalargumentSchema?:Record<string,unknown>
Defined in: command.svelte.ts:77
Optional structured argument schema for declarative callers.
callback?
Section titled “callback?”
optionalcallback?: (…args) =>any
Defined in: command.svelte.ts:111
Simple callback, triggered globally.
Parameters
Section titled “Parameters”…any[]
Returns
Section titled “Returns”any
Remarks
Section titled “Remarks”Example:
this.addCommand({ id: "print-greeting-to-console", name: "Print greeting to console", callback: () => { console.log("Hey, you!"); },});category?
Section titled “category?”
optionalcategory?:string
Defined in: command.svelte.ts:53
Optional command category used by declarative contribution surfaces.
checkCallback?
Section titled “checkCallback?”
optionalcheckCallback?: (checking) =>boolean|void
Defined in: command.svelte.ts:147
Complex callback, overrides the simple callback. Used to ‘check’ whether your command can be performed in the current circumstances. For example, if your command requires the active focused pane to be a MarkdownView, then you should only return true if the condition is satisfied. Returning false or undefined causes the command to be hidden from the command palette.
Parameters
Section titled “Parameters”checking
Section titled “checking”boolean
Whether the command palette is just ‘checking’ if your command should show right now. If checking is true, then this function should not perform any action. If checking is false, then this function should perform the action.
Returns
Section titled “Returns”boolean | void
Whether this command can be executed at the moment.
Remarks
Section titled “Remarks”Example:
this.addCommand({ id: "example-command", name: "Example command", checkCallback: (checking: boolean) => { const value = getRequiredValue();
if (value) { if (!checking) { doCommand(value); } return true; }
return false; },});editorCallback?
Section titled “editorCallback?”
optionaleditorCallback?: (editor,ctx) =>any
Defined in: command.svelte.ts:168
A command callback that is only triggered when the user is in an editor.
Overrides callback and checkCallback
Parameters
Section titled “Parameters”editor
Section titled “editor”any
Returns
Section titled “Returns”any
Remarks
Section titled “Remarks”Example:
this.addCommand({ id: "example-command", name: "Example command", editorCallback: (editor: Editor, view: MarkdownView) => { const sel = editor.getSelection();
console.log(`You have selected: ${sel}`); },});editorCheckCallback?
Section titled “editorCheckCallback?”
optionaleditorCheckCallback?: (checking,editor,ctx) =>boolean|void
Defined in: command.svelte.ts:197
A command callback that is only triggered when the user is in an editor.
Overrides editorCallback, callback and checkCallback
Parameters
Section titled “Parameters”checking
Section titled “checking”boolean
editor
Section titled “editor”any
Returns
Section titled “Returns”boolean | void
Remarks
Section titled “Remarks”Example:
this.addCommand({ id: "example-command", name: "Example command", editorCheckCallback: ( checking: boolean, editor: Editor, view: MarkdownView, ) => { const value = getRequiredValue();
if (value) { if (!checking) { doCommand(value); }
return true; }
return false; },});hotkeys?
Section titled “hotkeys?”
optionalhotkeys?:Hotkey[]
Defined in: command.svelte.ts:210
Sets the default hotkey. It is recommended for plugins to avoid setting default hotkeys if possible, to avoid conflicting hotkeys with one that’s set by the user, even though customized hotkeys have higher priority.
optionalicon?:string
Defined in: command.svelte.ts:59
Icon ID to be used in the toolbar.
id:
string
Defined in: command.svelte.ts:35
Globally unique ID to identify this command.
mobileOnly?
Section titled “mobileOnly?”
optionalmobileOnly?:boolean
Defined in: command.svelte.ts:86
name:
string
Defined in: command.svelte.ts:41
Human friendly name for searching.
repeatable?
Section titled “repeatable?”
optionalrepeatable?:boolean
Defined in: command.svelte.ts:93
Whether holding the hotkey should repeatedly trigger this command.
Default Value
Section titled “Default Value”false@publicsourcePlugin?
Section titled “sourcePlugin?”
optionalsourcePlugin?:string
Defined in: command.svelte.ts:65
Plugin ID that owns this command.
title?
Section titled “title?”
optionaltitle?:string
Defined in: command.svelte.ts:47
Human-friendly command title without source prefixes.
optionalwhen?:string
Defined in: command.svelte.ts:84
Declarative context expression that must evaluate truthy before the command is visible or executable.