forked from mirror/readline
fix deleteword/kill
This commit is contained in:
parent
9c65cb7ccf
commit
c9aba7b858
|
@ -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:
|
||||
|
|
16
runebuf.go
16
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] == ' ' {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue