[history] fix bug that check equals with previous command (#49)

This commit is contained in:
chzyer 2016-04-21 14:10:50 +08:00
parent 1e0917c739
commit dc5da28fbf
1 changed files with 10 additions and 4 deletions

View File

@ -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 {