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
This commit is contained in:
Paul Ouellette authored and GitHub committed 2023-04-01 19:25:55 +03:00
1 parent 70171adf40
commit f563263add
1 file changed
+6 -6
+6 -6
View File
@@ -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()))
}
}