Skip to content

Commit

Permalink
Completion: always insert longest match (#1184)
Browse files Browse the repository at this point in the history
Previously, longest common match completion would only apply if there
was a word before the cursor.

Suggested in #1090
  • Loading branch information
p-ouellette committed Apr 1, 2023
1 parent 70171ad commit f563263
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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()))
}
}

Expand Down

0 comments on commit f563263

Please sign in to comment.