summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-06-18 14:06:20 -0500
committeradamdottv <[email protected]>2025-06-18 14:06:20 -0500
commit1d0bfc2b2ac2bad3a646c6adf43aa112d47c3f07 (patch)
tree4bde15459d6da76e9c8fad3a85a29503e115e116
parentbd46cf0f868293b501874c1f04632ced3bec7b81 (diff)
downloadopencode-1d0bfc2b2ac2bad3a646c6adf43aa112d47c3f07.tar.gz
opencode-1d0bfc2b2ac2bad3a646c6adf43aa112d47c3f07.zip
fix(tui): help dialog sorting
-rw-r--r--packages/tui/internal/commands/command.go20
-rw-r--r--packages/tui/internal/components/dialog/help.go4
-rw-r--r--packages/tui/internal/tui/tui.go2
3 files changed, 17 insertions, 9 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
}
diff --git a/packages/tui/internal/components/dialog/help.go b/packages/tui/internal/components/dialog/help.go
index 1886714e4..6041fd5e7 100644
--- a/packages/tui/internal/components/dialog/help.go
+++ b/packages/tui/internal/components/dialog/help.go
@@ -15,7 +15,7 @@ type helpDialog struct {
width int
height int
modal *modal.Modal
- commands commands.CommandRegistry
+ commands []commands.Command
}
func (h *helpDialog) Init() tea.Cmd {
@@ -80,7 +80,7 @@ type HelpDialog interface {
layout.Modal
}
-func NewHelpDialog(commands commands.CommandRegistry) HelpDialog {
+func NewHelpDialog(commands []commands.Command) HelpDialog {
return &helpDialog{
commands: commands,
modal: modal.New(),
diff --git a/packages/tui/internal/tui/tui.go b/packages/tui/internal/tui/tui.go
index 3b6b44eff..9fe52cdab 100644
--- a/packages/tui/internal/tui/tui.go
+++ b/packages/tui/internal/tui/tui.go
@@ -284,7 +284,7 @@ func (a appModel) executeCommand(command commands.Command) (tea.Model, tea.Cmd)
}
switch command.Name {
case commands.AppHelpCommand:
- helpDialog := dialog.NewHelpDialog(a.app.Commands)
+ helpDialog := dialog.NewHelpDialog(a.app.Commands.Sorted())
a.modal = helpDialog
case commands.EditorOpenCommand:
if a.app.IsBusy() {