From e3e573aa21f1b8930f1dae69c9d36631aba213c5 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Fri, 8 Apr 2016 04:01:57 +0200 Subject: [PATCH] Auto complete with space prefixed line (#46) * auto-complete gets displayed even with space characters prefixing the line * demo test back to chzyer; --- complete_helper.go | 2 +- runes.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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:] +}