From f563263addd7d62bf410291c9f16095a0e34345c Mon Sep 17 00:00:00 2001 From: Paul Ouellette Date: Sat, 1 Apr 2023 11:25:55 -0500 Subject: [PATCH] Completion: always insert longest match (#1184) Previously, longest common match completion would only apply if there was a word before the cursor. Suggested in #1090 --- complete.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/complete.go b/complete.go index 70f70b72..dc76786f 100644 --- a/complete.go +++ b/complete.go @@ -339,14 +339,14 @@ func matchFile(s string) (matches []string, longest []rune) { } matches = append(matches, item) - if longest != nil { - longest = matchLongest(longest, []rune(name)) - } else if s != "" { + if longest == nil { if f.Mode().IsRegular() { longest = []rune(name + " ") } else { longest = []rune(name + escape(string(filepath.Separator))) } + } else { + longest = matchLongest(longest, []rune(name)) } } @@ -438,10 +438,10 @@ func completeFile(acc []rune) (matches []string, longestAcc []rune) { matches = append(matches, f.Name()) - if longestAcc != nil { - longestAcc = matchLongest(longestAcc, []rune(f.Name())) - } else if s != "" { + if longestAcc == nil { longestAcc = []rune(f.Name()) + } else { + longestAcc = matchLongest(longestAcc, []rune(f.Name())) } }