Auto complete with space prefixed line (#46)

* auto-complete gets displayed even with space characters prefixing the line

* demo test back to chzyer;
This commit is contained in:
Michal Pristas 2016-04-08 04:01:57 +02:00 committed by chzyer
parent f2a9cba613
commit e3e573aa21
2 changed files with 12 additions and 1 deletions

View File

@ -73,7 +73,7 @@ func (p *PrefixCompleter) Do(line []rune, pos int) (newLine [][]rune, offset int
} }
func Do(p PrefixCompleterInterface, line []rune, pos int) (newLine [][]rune, offset int) { func Do(p PrefixCompleterInterface, line []rune, pos int) (newLine [][]rune, offset int) {
line = line[:pos] line = runes.TrimSpaceLeft(line[:pos])
goNext := false goNext := false
var lineCompleter PrefixCompleterInterface var lineCompleter PrefixCompleterInterface
for _, child := range p.GetChildren() { for _, child := range p.GetChildren() {

View File

@ -154,3 +154,14 @@ aggregate:
} }
return return
} }
func (Runes) TrimSpaceLeft(in []rune) []rune {
firstIndex := len(in)
for i, r := range in {
if unicode.IsSpace(r) == false {
firstIndex = i
break
}
}
return in[firstIndex:]
}