Skip to content

EditorCommandHandler.shouldAddToViewportMenu method

EditorCommandHandler › shouldAddToViewportMenu

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.

Signature:

shouldAddToViewportMenu(_view: MarkdownView, _mode: string, _source: string): boolean

Parameters:

ParameterTypeDescription
_viewMarkdownViewThe markdown view the menu was raised over.
_modestringThe view mode ('source' or 'preview').
_sourcestringWhat raised the menu.

Returns: booleanWhether to add to the viewport menu.