Skip to content

Commit

Permalink
[history] fix bug that check equals with previous command (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
chzyer committed Apr 21, 2016
1 parent 1e0917c commit dc5da28
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions history.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -214,20 +219,21 @@ 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++
return nil
}
}
}

if len(current) == 0 {
o.current = o.history.Back()
if o.current != nil {
Expand Down

0 comments on commit dc5da28

Please sign in to comment.