Behaviour for picker sources.
A source provides candidates for a picker and handles the select/cancel actions. Implementing this behaviour is all that's needed to add a new picker-powered feature — no changes to the editor core required.
Callbacks
candidates/1— returns the list of picker items given some contexton_select/2— called when the user selects an item; returns new editor stateon_cancel/1— called when the user cancels; returns new editor statepreview?/0— whether navigating the picker should preview the selection (default: false)title/0— the picker title shown in the separator bar
Example
defmodule MySource do
@behaviour MingaEditor.UI.Picker.Source
@impl true
def title, do: "My picker"
@impl true
def candidates(_context), do: [{:a, "item a", "description"}]
@impl true
def on_select(item, state), do: state
@impl true
def on_cancel(state), do: state
end
Summary
Types
An alternative action: display name and action identifier.
Picker layout: bottom-anchored (default) or centered floating window.
Callbacks
Returns the list of alternative actions available for a picker item. The first entry is conventionally the default action.
Returns the list of candidates to display in the picker.
Whether the picker should stay open after selecting an item.
Defaults to false (picker closes on Enter). When true, the picker
calls on_select, then refreshes items via candidates/1 so the
user can see updated state (e.g., tool install status changes).
Returns the preferred layout for this picker source.
Defaults to :bottom (Emacs-style minibuffer overlay).
:centered renders inside a FloatingWindow overlay.
Executes an alternative action on a picker item. Called when the user selects an action from the C-o menu.
Called when the user cancels the picker. Returns the new editor state.
Called when the user selects an item. Returns the new editor state.
Whether navigating the picker should live-preview the selection.
Returns the display title for this picker source.
Functions
Returns the actions for an item, or an empty list if the source doesn't support actions.
Returns whether a source module supports alternative actions (C-o menu).
Returns whether the picker should stay open after selecting an item.
Returns the preferred layout for a source, defaulting to :bottom.
Returns whether a source module supports preview.
Falls back to false if the callback is not implemented.
Default on_cancel implementation: restores the buffer that was active
when the picker opened (stored in picker_ui.restore), or returns state
unchanged if no restore index was saved.
Types
Callbacks
@callback actions(MingaEditor.UI.Picker.item()) :: [action_entry()]
Returns the list of alternative actions available for a picker item. The first entry is conventionally the default action.
@callback candidates(MingaEditor.UI.Picker.Context.t()) :: [MingaEditor.UI.Picker.item()]
Returns the list of candidates to display in the picker.
@callback keep_open_on_select?() :: boolean()
Whether the picker should stay open after selecting an item.
Defaults to false (picker closes on Enter). When true, the picker
calls on_select, then refreshes items via candidates/1 so the
user can see updated state (e.g., tool install status changes).
@callback layout() :: layout()
Returns the preferred layout for this picker source.
Defaults to :bottom (Emacs-style minibuffer overlay).
:centered renders inside a FloatingWindow overlay.
@callback on_action(atom(), MingaEditor.UI.Picker.item(), state :: term()) :: term()
Executes an alternative action on a picker item. Called when the user selects an action from the C-o menu.
Called when the user cancels the picker. Returns the new editor state.
@callback on_select(MingaEditor.UI.Picker.item(), state :: term()) :: term()
Called when the user selects an item. Returns the new editor state.
@callback preview?() :: boolean()
Whether navigating the picker should live-preview the selection.
@callback title() :: String.t()
Returns the display title for this picker source.
Functions
@spec actions(module(), MingaEditor.UI.Picker.item()) :: [action_entry()]
Returns the actions for an item, or an empty list if the source doesn't support actions.
Returns whether a source module supports alternative actions (C-o menu).
Returns whether the picker should stay open after selecting an item.
Returns the preferred layout for a source, defaulting to :bottom.
Returns whether a source module supports preview.
Falls back to false if the callback is not implemented.
Default on_cancel implementation: restores the buffer that was active
when the picker opened (stored in picker_ui.restore), or returns state
unchanged if no restore index was saved.