EditorCommandHandler
Command handler for editor commands.
Subclasses override canExecuteEditor and executeEditor to provide behavior. Optionally integrates with the editor context menu via shouldAddToEditorMenu, and with the markdown viewport (margin) menu via shouldAddToViewportMenu.
Import:
import { EditorCommandHandler } from 'obsidian-dev-utils/obsidian/command-handlers/editor-command-handler';Signature:
export class EditorCommandHandler extends CommandHandlerExtends: CommandHandler
Constructor
new EditorCommandHandler(params: EditorCommandHandlerConstructorParams)Creates a new editor command handler.
Properties
| Property | Type | Description |
|---|---|---|
| icon | IconName | The icon for the command. (Inherited from CommandHandler) |
| id | string | The ID of the command. (Inherited from CommandHandler) |
| name | string | The display name of the command. (Inherited from CommandHandler) |
Methods
| Method | Returns | Description |
|---|---|---|
| buildCommand() | Command | Builds a plain Obsidian Command object with an editorCheckCallback. |
| canExecuteEditor(_editor, _context) | boolean | Checks whether the command can execute for the given editor and context. |
| executeEditor(editor, context) | Promisable<void> | Executes the command for the given editor and context. |
| onRegistered(context) | Promise<void> | Registers the editor-menu and markdown-viewport-menu event handlers. Both are registered unconditionally; whether an item actually appears is decided per menu render by shouldAddToEditorMenu / shouldAddToViewportMenu, which both default to false. |
| shouldAddCommandToSubmenu() | boolean | undefined | Gets whether to add the command to a submenu. |
| shouldAddToCommandPalette() | boolean | Checks whether the command should appear in the command palette. |
| shouldAddToEditorMenu(_editor, _context) | boolean | Checks whether the command should appear in the editor context menu. |
| shouldAddToViewportMenu(_view, _mode, _source) | boolean | Checks whether the command should appear in the markdown viewport (margin) context menu. That is the menu carrying Readable line length / Line numbers / Inline title, raised by right-clicking the empty space beside the text or the line-number gutter — a menu shouldAddToEditorMenu can never reach, because a margin click lands outside the editor's contentDOM. It is a natural home for whole-note commands once the editor menu gets crowded.mode and source are passed through rather than filtered here: whether a command belongs in reading mode is the consuming plugin's call. Note that Obsidian 1.13.7 always passes 'gutter' as source, so only mode currently discriminates - see MarkdownViewportMenuEventHandler. |