fixes #264 tcell breaks grapheme clusters

This commit is contained in:
Garrett D'Amore 2019-03-18 23:41:32 -07:00
parent 77ab683d7d
commit d195cc757c
2 changed files with 5 additions and 19 deletions

View File

@ -1,4 +1,4 @@
// Copyright 2015 The TCell Authors
// Copyright 2019 The TCell Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use file except in compliance with the License.
@ -22,7 +22,7 @@ import (
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/encoding"
"github.com/mattn/go-runewidth"
runewidth "github.com/mattn/go-runewidth"
)
var row = 0
@ -127,7 +127,7 @@ func main() {
putln(s, "ZWJ: \U0001f9db\u200d\u2640 (female vampire)")
putln(s, "ZWJ: \U0001f9db\u200d\u2642 (male vampire)")
putln(s, "Family: \U0001f469\u200d\U0001f467\u200d\U0001f467 (woman girl girl)\n")
putln(s, "Region: \U0001f1fa\U0001f1f8 (USA! USA!)\n")
putln(s, "")
putln(s, "Box:")
putln(s, string([]rune{

18
cell.go
View File

@ -1,4 +1,4 @@
// Copyright 2015 The TCell Authors
// Copyright 2019 The TCell Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use file except in compliance with the License.
@ -15,7 +15,7 @@
package tcell
import (
"github.com/mattn/go-runewidth"
runewidth "github.com/mattn/go-runewidth"
)
type cell struct {
@ -49,20 +49,6 @@ func (cb *CellBuffer) SetContent(x int, y int,
c := &cb.cells[(y*cb.w)+x]
c.currComb = append([]rune{}, combc...)
i := 0
for i < len(c.currComb) {
r := c.currComb[i]
if r == '\u200d' {
i += 2
continue
}
if runewidth.RuneWidth(r) != 0 {
// not a combining character, yank it
c.currComb = append(c.currComb[:i-1], c.currComb[i+1:]...)
continue
}
i++
}
if c.currMain != mainc {
c.width = runewidth.RuneWidth(mainc)