Documentation
¶
Overview ¶
Package palette implements the command palette UI for fuzzy searching and executing commands, with support for context filtering and keybinding display.
Index ¶
- func GroupEntriesByLayer(entries []PaletteEntry) map[Layer][]PaletteEntry
- func ScoreEntry(entry *PaletteEntry, query string)
- func SortEntries(entries []PaletteEntry)
- type CommandSelectedMsg
- type Layer
- type MatchRange
- type Model
- func (m Model) Cursor() int
- func (m Model) Filtered() []PaletteEntry
- func (m Model) Init() tea.Cmd
- func (m Model) MaxVisible() int
- func (m Model) Offset() int
- func (m *Model) Open(km *keymap.Registry, plugins []plugin.Plugin, ...)
- func (m Model) Query() string
- func (m Model) SelectedEntry() *PaletteEntry
- func (m *Model) SetSize(width, height int)
- func (m Model) ShowAllContexts() bool
- func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)
- func (m Model) View() string
- type PaletteEntry
- func BuildEntries(km *keymap.Registry, plugins []plugin.Plugin, ...) []PaletteEntry
- func FilterEntries(entries []PaletteEntry, query string) []PaletteEntry
- func FilterEntriesForContext(entries []PaletteEntry, activeContext string) []PaletteEntry
- func GroupEntriesByCommand(entries []PaletteEntry) []PaletteEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GroupEntriesByLayer ¶
func GroupEntriesByLayer(entries []PaletteEntry) map[Layer][]PaletteEntry
GroupEntriesByLayer groups entries by their layer for display.
func ScoreEntry ¶
func ScoreEntry(entry *PaletteEntry, query string)
ScoreEntry scores a palette entry against a query. Combines scores from multiple fields with weighting.
func SortEntries ¶
func SortEntries(entries []PaletteEntry)
SortEntries sorts entries by score descending, then by layer, then alphabetically.
Types ¶
type CommandSelectedMsg ¶
CommandSelectedMsg is sent when a command is selected from the palette.
type MatchRange ¶
MatchRange represents a contiguous range of matched characters.
func FuzzyMatch ¶
func FuzzyMatch(query, target string) (int, []MatchRange)
FuzzyMatch scores how well query matches target string. Returns score (0 = no match) and ranges for highlighting. Scoring:
- Consecutive matches: bonus per consecutive char
- Word start matches (after /, _, -, .): large bonus
- Shorter targets: small bonus
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is the command palette state.
func (Model) Filtered ¶
func (m Model) Filtered() []PaletteEntry
Filtered returns the currently filtered entries.
func (*Model) Open ¶
func (m *Model) Open(km *keymap.Registry, plugins []plugin.Plugin, activeContext, pluginContext string)
Open prepares the palette for display. Rebuilds entries based on current context.
func (Model) SelectedEntry ¶
func (m Model) SelectedEntry() *PaletteEntry
SelectedEntry returns the currently selected entry, if any.
func (Model) ShowAllContexts ¶
ShowAllContexts returns whether all contexts mode is active.
type PaletteEntry ¶
type PaletteEntry struct {
Key string // Display key(s): "s" or "ctrl+s"
CommandID string // Command ID
Name string // Short name
Description string // Full description
Category plugin.Category // Category for grouping
Context string // Source context
Layer Layer // Which layer: CurrentMode, Plugin, Global
Score int // Fuzzy match score (computed during search)
MatchRanges []MatchRange // For highlighting matches in name
ContextCount int // Number of contexts this command appears in (for grouped display)
}
PaletteEntry represents a single searchable entry in the command palette.
func BuildEntries ¶
func BuildEntries(km *keymap.Registry, plugins []plugin.Plugin, activeContext, pluginContext string) []PaletteEntry
BuildEntries aggregates commands from keymap bindings and plugin commands. activeContext is the current focus context (e.g., "git-diff"). pluginContext is the base plugin context (e.g., "git-status").
func FilterEntries ¶
func FilterEntries(entries []PaletteEntry, query string) []PaletteEntry
FilterEntries filters and scores entries against a query. Returns entries sorted by relevance.
func FilterEntriesForContext ¶
func FilterEntriesForContext(entries []PaletteEntry, activeContext string) []PaletteEntry
FilterEntriesForContext returns entries for a specific context + global only. This eliminates duplicates since each command appears at most once per context.
func GroupEntriesByCommand ¶
func GroupEntriesByCommand(entries []PaletteEntry) []PaletteEntry
GroupEntriesByCommand groups entries by CommandID and marks context count. Returns one entry per command with ContextCount set for commands in multiple contexts.