Skip to content

Commit

Permalink
Merge pull request #84 from rogpeppe-contrib/017-fix-completion
Browse files Browse the repository at this point in the history
cmd/acme/internal/fileload: fix completion logic
  • Loading branch information
rogpeppe authored Nov 18, 2021
2 parents 6faf3d8 + e402fdb commit 4b1f37b
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions cmd/acme/internal/fileload/text1.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,38 +158,27 @@ func Textcomplete(t *wind.Text) []rune {
return nil
}
nstr := wind.Textfilewidth(t, t.Q0, true)
str := make([]rune, nstr)
str := make([]rune, 0, nstr)
npath := wind.Textfilewidth(t, t.Q0-nstr, false)
path_ := make([]rune, npath)
path_ := make([]rune, 0, npath)

q := t.Q0 - nstr
var i int
for i = 0; i < nstr; i++ {
str[i] = t.RuneAt(q)
q++
for q := t.Q0 - nstr; q < t.Q0; q++ {
str = append(str, t.RuneAt(q))
}
q = t.Q0 - nstr - npath
for i = 0; i < npath; i++ {
path_[i] = t.RuneAt(q)
q++
for q := t.Q0 - nstr - npath; q < t.Q0-nstr; q++ {
path_ = append(path_, t.RuneAt(q))
}
var dir []rune
// is path rooted? if not, we need to make it relative to window path
if npath > 0 && path_[0] == '/' {
dir = path_
} else {
dir = wind.Dirname(t, nil)
tmp := make([]rune, 200)
if len(dir)+1+npath > len(tmp) {
return nil
}
if len(dir) == 0 {
dir = runes.Clone([]rune("."))
dir = []rune{'.'}
}
copy(tmp, dir)
tmp[len(dir)] = '/'
copy(tmp[len(dir)+1:], path_)
dir = tmp
dir = append(dir, '/')
dir = append(dir, path_...)
dir = runes.CleanPath(dir)
}

Expand All @@ -209,7 +198,7 @@ func Textcomplete(t *wind.Text) []rune {
more = ": no matches in:"
}
alog.Printf("%s%s%s*%s\n", string(dir), sep, string(str), more)
for i = 0; i < len(c.Files); i++ {
for i := 0; i < len(c.Files); i++ {
alog.Printf(" %s\n", c.Files[i])
}
}
Expand Down

0 comments on commit 4b1f37b

Please sign in to comment.