fix(tui): help dialog sorting

This commit is contained in:
adamdottv
2025-06-18 14:06:20 -05:00
parent bd46cf0f86
commit 1d0bfc2b2a
3 changed files with 17 additions and 9 deletions

View File

@@ -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
}