fixing deadloop when input is filtered

This commit is contained in:
ChenYe 2022-07-15 20:48:48 +08:00
parent 8e4bd417b9
commit 7f93d88cd5
2 changed files with 5 additions and 3 deletions

View File

@ -109,10 +109,12 @@ func (o *Operation) ioloop() {
keepInSearchMode := false keepInSearchMode := false
keepInCompleteMode := false keepInCompleteMode := false
r := o.t.ReadRune() r := o.t.ReadRune()
if o.GetConfig().FuncFilterInputRune != nil { if o.GetConfig().FuncFilterInputRune != nil {
var process bool var process bool
r, process = o.GetConfig().FuncFilterInputRune(r) r, process = o.GetConfig().FuncFilterInputRune(r)
if !process { if !process {
o.t.KickRead()
o.buf.Refresh(nil) // to refresh the line o.buf.Refresh(nil) // to refresh the line
continue // ignore this rune continue // ignore this rune
} }

View File

@ -35,7 +35,7 @@ type RuneBuffer struct {
sync.Mutex sync.Mutex
} }
func (r* RuneBuffer) pushKill(text []rune) { func (r *RuneBuffer) pushKill(text []rune) {
r.lastKill = append([]rune{}, text...) r.lastKill = append([]rune{}, text...)
} }
@ -221,7 +221,7 @@ func (r *RuneBuffer) DeleteWord() {
} }
for i := init + 1; i < len(r.buf); i++ { for i := init + 1; i < len(r.buf); i++ {
if !IsWordBreak(r.buf[i]) && IsWordBreak(r.buf[i-1]) { 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.Refresh(func() {
r.buf = append(r.buf[:r.idx], r.buf[i-1:]...) r.buf = append(r.buf[:r.idx], r.buf[i-1:]...)
}) })
@ -350,7 +350,7 @@ func (r *RuneBuffer) Yank() {
return return
} }
r.Refresh(func() { 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.buf[:r.idx]...)
buf = append(buf, r.lastKill...) buf = append(buf, r.lastKill...)
buf = append(buf, r.buf[r.idx:]...) buf = append(buf, r.buf[r.idx:]...)