diff --git a/complete_helper.go b/complete_helper.go index 430fbf3..16bb36a 100644 --- a/complete_helper.go +++ b/complete_helper.go @@ -3,6 +3,8 @@ package readline import ( "bytes" "strings" + + "github.com/chzyer/readline/runes" ) type PrefixCompleterInterface interface { @@ -73,7 +75,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..bf7959e 100644 --- a/runes.go +++ b/runes.go @@ -154,3 +154,14 @@ aggregate: } return } + +func TrimSpaceLeft(in []rune) []rune { + firstIndex := 0 + for i, r := range in { + if unicode.IsSpace(r) == false { + firstIndex = i + break + } + } + return in[firstIndex:] +}