forked from mirror/readline
fix deleteword/kill
This commit is contained in:
parent
9c65cb7ccf
commit
c9aba7b858
|
@ -20,6 +20,7 @@ type Operation struct {
|
||||||
const (
|
const (
|
||||||
CharLineStart = 0x1
|
CharLineStart = 0x1
|
||||||
CharLineEnd = 0x5
|
CharLineEnd = 0x5
|
||||||
|
CharKill = 11
|
||||||
CharNext = 0xe
|
CharNext = 0xe
|
||||||
CharPrev = 0x10
|
CharPrev = 0x10
|
||||||
CharBackward = 0x2
|
CharBackward = 0x2
|
||||||
|
@ -58,6 +59,8 @@ func (l *Operation) ioloop() {
|
||||||
for {
|
for {
|
||||||
r := l.t.ReadRune()
|
r := l.t.ReadRune()
|
||||||
switch r {
|
switch r {
|
||||||
|
case CharKill:
|
||||||
|
l.buf.Kill()
|
||||||
case MetaNext:
|
case MetaNext:
|
||||||
l.buf.MoveToNextWord()
|
l.buf.MoveToNextWord()
|
||||||
case MetaPrev:
|
case MetaPrev:
|
||||||
|
|
16
runebuf.go
16
runebuf.go
|
@ -84,16 +84,18 @@ func (r *RuneBuffer) DeleteWord() {
|
||||||
if r.idx == len(r.buf) {
|
if r.idx == len(r.buf) {
|
||||||
return
|
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] == ' ' {
|
if r.buf[i] != ' ' && r.buf[i-1] == ' ' {
|
||||||
r.buf = append(r.buf[:r.idx], r.buf[i-1:]...)
|
r.buf = append(r.buf[:r.idx], r.buf[i-1:]...)
|
||||||
r.Refresh(r.idx-i+1, 0)
|
r.Refresh(r.idx-i+1, 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
length := len(r.buf)
|
r.Kill()
|
||||||
r.buf = r.buf[:r.idx]
|
|
||||||
r.Refresh(length-r.idx, 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RuneBuffer) MoveToPrevWord() {
|
func (r *RuneBuffer) MoveToPrevWord() {
|
||||||
|
@ -115,6 +117,12 @@ func (r *RuneBuffer) SetIdx(idx int) (change int) {
|
||||||
return r.idx - i
|
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() {
|
func (r *RuneBuffer) MoveToNextWord() {
|
||||||
for i := r.idx + 1; i < len(r.buf); i++ {
|
for i := r.idx + 1; i < len(r.buf); i++ {
|
||||||
if r.buf[i] != ' ' && r.buf[i-1] == ' ' {
|
if r.buf[i] != ' ' && r.buf[i-1] == ' ' {
|
||||||
|
|
|
@ -100,7 +100,7 @@ func (t *Terminal) ioloop() {
|
||||||
isEscape = true
|
isEscape = true
|
||||||
case CharEnter, CharEnter2, KeyPrevChar, KeyNextChar, KeyDelete:
|
case CharEnter, CharEnter2, KeyPrevChar, KeyNextChar, KeyDelete:
|
||||||
fallthrough
|
fallthrough
|
||||||
case CharLineEnd, CharLineStart, CharNext, CharPrev:
|
case CharLineEnd, CharLineStart, CharNext, CharPrev, CharKill:
|
||||||
t.outchan <- r
|
t.outchan <- r
|
||||||
default:
|
default:
|
||||||
println("np:", r)
|
println("np:", r)
|
||||||
|
|
Loading…
Reference in New Issue