Skip to content

Commit

Permalink
fixing deadloop when input is filtered
Browse files Browse the repository at this point in the history
  • Loading branch information
chzyer committed Jul 15, 2022
1 parent 8e4bd41 commit 7f93d88
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ func (o *Operation) ioloop() {
keepInSearchMode := false
keepInCompleteMode := false
r := o.t.ReadRune()

if o.GetConfig().FuncFilterInputRune != nil {
var process bool
r, process = o.GetConfig().FuncFilterInputRune(r)
if !process {
o.t.KickRead()
o.buf.Refresh(nil) // to refresh the line
continue // ignore this rune
}
Expand Down
6 changes: 3 additions & 3 deletions runebuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type RuneBuffer struct {
sync.Mutex
}

func (r* RuneBuffer) pushKill(text []rune) {
func (r *RuneBuffer) pushKill(text []rune) {
r.lastKill = append([]rune{}, text...)
}

Expand Down Expand Up @@ -221,7 +221,7 @@ func (r *RuneBuffer) DeleteWord() {
}
for i := init + 1; i < len(r.buf); i++ {
if !IsWordBreak(r.buf[i]) && IsWordBreak(r.buf[i-1]) {
r.pushKill(r.buf[r.idx:i-1])
r.pushKill(r.buf[r.idx : i-1])
r.Refresh(func() {
r.buf = append(r.buf[:r.idx], r.buf[i-1:]...)
})
Expand Down Expand Up @@ -350,7 +350,7 @@ func (r *RuneBuffer) Yank() {
return
}
r.Refresh(func() {
buf := make([]rune, 0, len(r.buf) + len(r.lastKill))
buf := make([]rune, 0, len(r.buf)+len(r.lastKill))
buf = append(buf, r.buf[:r.idx]...)
buf = append(buf, r.lastKill...)
buf = append(buf, r.buf[r.idx:]...)
Expand Down

0 comments on commit 7f93d88

Please sign in to comment.