diff --git a/complete_helper.go b/complete_helper.go index 430fbf3..f609d44 100644 --- a/complete_helper.go +++ b/complete_helper.go @@ -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) { - line = line[:pos] + line = runes.TrimSpaceLeft(line[:pos]) goNext := false var lineCompleter PrefixCompleterInterface for _, child := range p.GetChildren() { diff --git a/runes.go b/runes.go index b0a878b..b85af7a 100644 --- a/runes.go +++ b/runes.go @@ -154,3 +154,14 @@ aggregate: } 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:] +}