diff --git a/choose/command.go b/choose/command.go index f96b1beba..1962b5079 100644 --- a/choose/command.go +++ b/choose/command.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "os" + "slices" "strings" "github.com/charmbracelet/huh" @@ -44,6 +45,12 @@ func (o Options) Run() error { theme.Focused.SelectedPrefix = o.SelectedItemStyle.ToLipgloss().SetString(o.SelectedPrefix) theme.Focused.UnselectedPrefix = o.ItemStyle.ToLipgloss().SetString(o.UnselectedPrefix) + if o.Ordered { + slices.SortFunc(options, func(a, b huh.Option[string]) int { + return strings.Compare(a.Key, b.Key) + }) + } + for _, s := range o.Selected { for i, opt := range options { if s == opt.Key || s == opt.Value {