diff --git a/operation.go b/operation.go index d9dc4c6..01373b4 100644 --- a/operation.go +++ b/operation.go @@ -20,6 +20,7 @@ type Operation struct { const ( CharLineStart = 0x1 CharLineEnd = 0x5 + CharKill = 11 CharNext = 0xe CharPrev = 0x10 CharBackward = 0x2 @@ -58,6 +59,8 @@ func (l *Operation) ioloop() { for { r := l.t.ReadRune() switch r { + case CharKill: + l.buf.Kill() case MetaNext: l.buf.MoveToNextWord() case MetaPrev: diff --git a/runebuf.go b/runebuf.go index 9d75a59..9435a09 100644 --- a/runebuf.go +++ b/runebuf.go @@ -84,16 +84,18 @@ func (r *RuneBuffer) DeleteWord() { if r.idx == len(r.buf) { return } - for i := r.idx + 1; i < len(r.buf); i++ { + init := r.idx + for init < len(r.buf) && r.buf[init] == ' ' { + init++ + } + for i := init + 1; i < len(r.buf); i++ { if r.buf[i] != ' ' && r.buf[i-1] == ' ' { r.buf = append(r.buf[:r.idx], r.buf[i-1:]...) r.Refresh(r.idx-i+1, 0) return } } - length := len(r.buf) - r.buf = r.buf[:r.idx] - r.Refresh(length-r.idx, 0) + r.Kill() } func (r *RuneBuffer) MoveToPrevWord() { @@ -115,6 +117,12 @@ func (r *RuneBuffer) SetIdx(idx int) (change int) { return r.idx - i } +func (r *RuneBuffer) Kill() { + length := len(r.buf) + r.buf = r.buf[:r.idx] + r.Refresh(r.idx-length, 0) +} + func (r *RuneBuffer) MoveToNextWord() { for i := r.idx + 1; i < len(r.buf); i++ { if r.buf[i] != ' ' && r.buf[i-1] == ' ' { diff --git a/terminal.go b/terminal.go index c895081..430f993 100644 --- a/terminal.go +++ b/terminal.go @@ -100,7 +100,7 @@ func (t *Terminal) ioloop() { isEscape = true case CharEnter, CharEnter2, KeyPrevChar, KeyNextChar, KeyDelete: fallthrough - case CharLineEnd, CharLineStart, CharNext, CharPrev: + case CharLineEnd, CharLineStart, CharNext, CharPrev, CharKill: t.outchan <- r default: println("np:", r)