Skip to content

obsidian/modals/suggest-modal-command-builder

A builder for a SuggestModal’s instruction bar.

SuggestModalCommandBuilder assembles the instruction bar shown at the bottom of a SuggestModal: keyboard-command hints (SuggestModalCommandBuilder.addKeyboardCommand), interactive checkboxes bound to a modifier+key shortcut (SuggestModalCommandBuilder.addCheckbox), and dropdowns bound to a modifier+key shortcut (SuggestModalCommandBuilder.addDropDown). Chain the add* calls, then apply everything to a modal with SuggestModalCommandBuilder.build:

new SuggestModalCommandBuilder()
.addKeyboardCommand({ key: 'Enter', modifiers: ['Mod'], onKey, purpose: 'to create' })
.addCheckbox({ key: '1', modifiers: ['Alt'], onChange, onInit, purpose: 'Fix footnotes' })
.build(modal);

SuggestModalCommandBuilder.build always registers the essential navigation/action key handlers, but only renders the instruction UI and registers the option-toggle shortcuts when SuggestModalCommandBuilderBuildOptions.shouldShowInstructions is true (the default).

ClassDescription
SuggestModalCommandBuilderBuilds a SuggestModal’s instruction bar from keyboard commands, interactive checkboxes, and dropdowns, then applies them to a modal via SuggestModalCommandBuilder.build.
InterfaceDescription
CheckboxCommandA checkbox command shown in a SuggestModal’s instruction bar and bound to a modifier+key shortcut that toggles it.
DropDownCommandA dropdown command shown in a SuggestModal’s instruction bar and bound to a modifier+key shortcut that cycles through its options.
KeyboardCommandA keyboard command shown in a SuggestModal’s instruction bar and optionally bound to a modifier+key handler.
SuggestModalCommandBuilderBuildOptionsOptions for SuggestModalCommandBuilder.build.