fixes #233 Want zero-width joiners support

This commit is contained in:
Garrett D'Amore 2018-09-05 18:42:39 -04:00
parent 61bec9bcda
commit 86147f14ef
2 changed files with 23 additions and 0 deletions

View File

@ -38,7 +38,22 @@ func puts(s tcell.Screen, style tcell.Style, x, y int, str string) {
i := 0 i := 0
var deferred []rune var deferred []rune
dwidth := 0 dwidth := 0
zwj := false
for _, r := range str { for _, r := range str {
if r == '\u200d' {
if len(deferred) == 0 {
deferred = append(deferred, ' ')
dwidth = 1
}
deferred = append(deferred, r)
zwj = true
continue
}
if zwj {
deferred = append(deferred, r)
zwj = false
continue
}
switch runewidth.RuneWidth(r) { switch runewidth.RuneWidth(r) {
case 0: case 0:
if len(deferred) == 0 { if len(deferred) == 0 {
@ -109,6 +124,10 @@ func main() {
putln(s, "Airplane: \u2708 (fly away)") putln(s, "Airplane: \u2708 (fly away)")
putln(s, "Command: \u2318 (mac clover key)") putln(s, "Command: \u2318 (mac clover key)")
putln(s, "Enclose: !\u20e3 (should be enclosed exclamation)") putln(s, "Enclose: !\u20e3 (should be enclosed exclamation)")
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, "") putln(s, "")
putln(s, "Box:") putln(s, "Box:")
putln(s, string([]rune{ putln(s, string([]rune{

View File

@ -52,6 +52,10 @@ func (cb *CellBuffer) SetContent(x int, y int,
i := 0 i := 0
for i < len(c.currComb) { for i < len(c.currComb) {
r := c.currComb[i] r := c.currComb[i]
if r == '\u200d' {
i += 2
continue
}
if runewidth.RuneWidth(r) != 0 { if runewidth.RuneWidth(r) != 0 {
// not a combining character, yank it // not a combining character, yank it
c.currComb = append(c.currComb[:i-1], c.currComb[i+1:]...) c.currComb = append(c.currComb[:i-1], c.currComb[i+1:]...)