summaryrefslogtreecommitdiffhomepage
path: root/packages/tui/internal/commands/command.go
diff options
context:
space:
mode:
Diffstat (limited to 'packages/tui/internal/commands/command.go')
-rw-r--r--packages/tui/internal/commands/command.go20
1 files changed, 14 insertions, 6 deletions
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
}