Skip to content

Commit

Permalink
fix: chinese corsor error chzyer#179
Browse files Browse the repository at this point in the history
  • Loading branch information
arrow2nd committed Nov 9, 2020
1 parent 155bce2 commit dc8be9e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 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 Expand Up @@ -527,8 +527,11 @@ func (r *RuneBuffer) getBackspaceSequence() []byte {
}
var buf []byte
for i := len(r.buf); i > r.idx; i-- {
// move input to the left of one
buf = append(buf, '\b')
// fix: chinese corsor error #179(@SilentTTxo) https://github.com/chzyer/readline/pull/179
// move input to the left of one, fix character where width > 1, such like chinese
for j := 0; j < runes.Width(r.buf[i-1]); j++ {
buf = append(buf, '\b')
}
if sep[i] {
// up one line, go to the start of the line and move cursor right to the end (r.width)
buf = append(buf, "\033[A\r"+"\033["+strconv.Itoa(r.width)+"C"...)
Expand Down

0 comments on commit dc8be9e

Please sign in to comment.