From 03359d475e5bc053b65bc4756dffe3d4450ca15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Prist=C3=A1=C5=A1=20Michal?= Date: Thu, 7 Apr 2016 09:55:33 +0200 Subject: [PATCH] fixed --- complete_helper.go | 4 +++- runes.go | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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:] +}