There should be no trailing space when completing directories for a file match based on patterns

This commit is contained in:
Kovid Goyal 2022-11-21 11:05:36 +05:30
parent 3c0667afd6
commit 4fc91dcc03
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 18 additions and 2 deletions

View File

@ -132,7 +132,7 @@ func (self *Completions) AddMatchGroup(title string) *MatchGroup {
return &ans
}
type CompletionFunc func(completions *Completions, word string, arg_num int)
type CompletionFunc = func(completions *Completions, word string, arg_num int)
func NamesCompleter(title string, names ...string) CompletionFunc {
return func(completions *Completions, word string, arg_num int) {

View File

@ -244,9 +244,25 @@ func make_completer(title string, relative_to relative_to, patterns []string, f
return func(completions *Completions, word string, arg_num int) {
q := f(word, cwd, lpats)
if len(q) > 0 {
dirs, files := make([]string, 0, len(q)), make([]string, 0, len(q))
for _, x := range q {
if strings.HasSuffix(x, "/") {
dirs = append(dirs, x)
} else {
files = append(files, x)
}
}
if len(dirs) > 0 {
mg := completions.AddMatchGroup("Directories")
mg.IsFiles = true
mg.NoTrailingSpace = true
for _, c := range dirs {
mg.AddMatch(c)
}
}
mg := completions.AddMatchGroup(title)
mg.IsFiles = true
for _, c := range q {
for _, c := range files {
mg.AddMatch(c)
}
}