From 25448a21d9e2371485964880e101365643a30097 Mon Sep 17 00:00:00 2001 From: TobiEiss Date: Fri, 4 Jan 2019 11:44:30 +0100 Subject: [PATCH] multiple possible matches --- completion.go | 1 + filter.go | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/completion.go b/completion.go index 2d19c1a..e1c8a4e 100644 --- a/completion.go +++ b/completion.go @@ -25,6 +25,7 @@ var ( type Suggest struct { Text string Description string + AlsoMatch []string } // CompletionManager manages which suggestion is now selected. diff --git a/filter.go b/filter.go index a5ec666..b18db91 100644 --- a/filter.go +++ b/filter.go @@ -59,12 +59,16 @@ func filterSuggestions(suggestions []Suggest, sub string, ignoreCase bool, funct ret := make([]Suggest, 0, len(suggestions)) for i := range suggestions { - c := suggestions[i].Text - if ignoreCase { - c = strings.ToUpper(c) - } - if function(c, sub) { - ret = append(ret, suggestions[i]) + possibleMatches := append(suggestions[i].AlsoMatch, suggestions[i].Text) + for _, possibleMatch := range possibleMatches { + c := possibleMatch + if ignoreCase { + c = strings.ToUpper(c) + } + if function(c, sub) { + ret = append(ret, suggestions[i]) + break + } } } return ret