From dc5da28fbf5287157fcd4719c794b59cd8852115 Mon Sep 17 00:00:00 2001 From: chzyer <0@0xdf.com> Date: Thu, 21 Apr 2016 14:10:50 +0800 Subject: [PATCH] [history] fix bug that check equals with previous command (#49) --- history.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/history.go b/history.go index 21e4d33..d71c44b 100644 --- a/history.go +++ b/history.go @@ -66,11 +66,16 @@ func (o *opHistory) historyUpdatePath(path string) { r := bufio.NewReader(o.fd) total := 0 for ; ; total++ { - line, err := r.ReadSlice('\n') + line, err := r.ReadString('\n') if err != nil { break } - o.Push([]rune(strings.TrimSpace(string(line)))) + // ignore the empty line + line = strings.TrimSpace(line) + if len(line) == 0 { + continue + } + o.Push([]rune(line)) o.Compact() } if total > o.cfg.HistoryLimit { @@ -214,13 +219,13 @@ func (o *opHistory) debug() { // save history func (o *opHistory) New(current []rune) (err error) { current = runes.Copy(current) + // if just use last command without modify // just clean lastest history if back := o.history.Back(); back != nil { prev := back.Prev() if prev != nil { - use := o.showItem(o.current.Value.(*hisItem)) - if runes.Equal(use, prev.Value.(*hisItem).Source) { + if runes.Equal(current, prev.Value.(*hisItem).Source) { o.current = o.history.Back() o.current.Value.(*hisItem).Clean() o.historyVer++ @@ -228,6 +233,7 @@ func (o *opHistory) New(current []rune) (err error) { } } } + if len(current) == 0 { o.current = o.history.Back() if o.current != nil {