fix: when input contains character where width > 1, such like chinese, cursor will in a wrong place, and never can back to the sentence`s head

This commit is contained in:
silentttxo 2019-07-17 19:18:41 +08:00
parent 2972be24d4
commit e668c71600
1 changed files with 4 additions and 2 deletions

View File

@ -527,8 +527,10 @@ func (r *RuneBuffer) getBackspaceSequence() []byte {
} }
var buf []byte var buf []byte
for i := len(r.buf); i > r.idx; i-- { for i := len(r.buf); i > r.idx; i-- {
// move input to the left of one // move input to the left of one, fix character where width > 1, such like chinese
buf = append(buf, '\b') for j:=0;j<runes.Width(r.buf[i-1]);j++ {
buf = append(buf, '\b')
}
if sep[i] { if sep[i] {
// up one line, go to the start of the line and move cursor right to the end (r.width) // 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"...) buf = append(buf, "\033[A\r"+"\033["+strconv.Itoa(r.width)+"C"...)