From 1d0bfc2b2ac2bad3a646c6adf43aa112d47c3f07 Mon Sep 17 00:00:00 2001 From: adamdottv <2363879+adamdottv@users.noreply.github.com> Date: Wed, 18 Jun 2025 14:06:20 -0500 Subject: fix(tui): help dialog sorting --- packages/tui/internal/commands/command.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'packages/tui/internal/commands') diff --git a/packages/tui/internal/commands/command.go b/packages/tui/internal/commands/command.go index 92e11c79f..ad7ccf30c 100644 --- a/packages/tui/internal/commands/command.go +++ b/packages/tui/internal/commands/command.go @@ -41,14 +41,12 @@ func (c Command) Keys() []string { type CommandRegistry map[CommandName]Command -func (r CommandRegistry) Matches(msg tea.KeyPressMsg, leader bool) []Command { - var matched []Command +func (r CommandRegistry) Sorted() []Command { + var commands []Command for _, command := range r { - if command.Matches(msg, leader) { - matched = append(matched, command) - } + commands = append(commands, command) } - slices.SortFunc(matched, func(a, b Command) int { + slices.SortFunc(commands, func(a, b Command) int { if a.Name == AppExitCommand { return 1 } @@ -57,6 +55,16 @@ func (r CommandRegistry) Matches(msg tea.KeyPressMsg, leader bool) []Command { } return strings.Compare(string(a.Name), string(b.Name)) }) + return commands +} + +func (r CommandRegistry) Matches(msg tea.KeyPressMsg, leader bool) []Command { + var matched []Command + for _, command := range r.Sorted() { + if command.Matches(msg, leader) { + matched = append(matched, command) + } + } return matched } -- cgit v1.2.3