summaryrefslogtreecommitdiffhomepage
path: root/packages/tui
diff options
context:
space:
mode:
authorRoderik van der Veer <[email protected]>2025-08-30 16:44:27 +0200
committerGitHub <[email protected]>2025-08-30 09:44:27 -0500
commit924e84b0deeebfb31384f221abbafa35cc0bc93b (patch)
treea2e5cc4900bbabf5090ca05ba68867648d288f9b /packages/tui
parent70db3cffb099ad863cdb6faf06759dc5c10d35bf (diff)
downloadopencode-924e84b0deeebfb31384f221abbafa35cc0bc93b.tar.gz
opencode-924e84b0deeebfb31384f221abbafa35cc0bc93b.zip
fix: change command selection to prefer exact matches over fuzzy sear… (#2314)
Diffstat (limited to 'packages/tui')
-rw-r--r--packages/tui/internal/completions/commands.go36
1 files changed, 35 insertions, 1 deletions
diff --git a/packages/tui/internal/completions/commands.go b/packages/tui/internal/completions/commands.go
index 2ffe3ea94..72e261f82 100644
--- a/packages/tui/internal/completions/commands.go
+++ b/packages/tui/internal/completions/commands.go
@@ -92,7 +92,41 @@ func (c *CommandCompletionProvider) GetChildEntries(
}
matches := fuzzy.RankFindFold(query, commandNames)
- sort.Sort(matches)
+
+ // Custom sort to prioritize exact matches
+ sort.Slice(matches, func(i, j int) bool {
+ // Check for exact match (case-insensitive)
+ iExact := strings.EqualFold(matches[i].Target, query)
+ jExact := strings.EqualFold(matches[j].Target, query)
+
+ // Exact matches come first
+ if iExact && !jExact {
+ return true
+ }
+ if !iExact && jExact {
+ return false
+ }
+
+ // Check for prefix match (case-insensitive)
+ iPrefix := strings.HasPrefix(strings.ToLower(matches[i].Target), strings.ToLower(query))
+ jPrefix := strings.HasPrefix(strings.ToLower(matches[j].Target), strings.ToLower(query))
+
+ // Prefix matches come before fuzzy matches
+ if iPrefix && !jPrefix {
+ return true
+ }
+ if !iPrefix && jPrefix {
+ return false
+ }
+
+ // Otherwise, sort by fuzzy match score (lower distance is better)
+ if matches[i].Distance != matches[j].Distance {
+ return matches[i].Distance < matches[j].Distance
+ }
+
+ // If distances are equal, sort by original index (stable sort)
+ return matches[i].OriginalIndex < matches[j].OriginalIndex
+ })
// Convert matches to completion items, deduplicating by command name
items := []CompletionSuggestion{}