Bugfixes related to zero-width joiners.

This commit is contained in:
Oliver 2018-09-26 12:03:53 +02:00
parent a677b985cc
commit bc39bf8d24
2 changed files with 10 additions and 5 deletions

View File

@ -938,7 +938,7 @@ func (t *TextView) Draw(screen tcell.Screen) {
runeSequence = append(runeSequence, ch)
continue
}
} else if runeSequence[len(runeSequence)-1] == '\u200d' {
} else if len(runeSequence) > 0 && runeSequence[len(runeSequence)-1] == '\u200d' {
// Keep collecting if the previous character was a zero-width joiner.
runeSequence = append(runeSequence, ch)
continue

13
util.go
View File

@ -388,10 +388,15 @@ func printWithStyle(screen tcell.Screen, text string, x, y, maxWidth, align int,
ch = ' '
chWidth = 1
}
} else if len(runeSequence) > 0 && runeSequence[len(runeSequence)-1] != '\u200d' {
// We have a character that doesn't follow a zero-width joiner. Flush all
// previous runes.
flush()
} else if len(runeSequence) > 0 {
if runeSequence[len(runeSequence)-1] != '\u200d' {
// We have a character that doesn't follow a zero-width joiner. Flush all
// previous runes.
flush()
} else {
// Characters after zero-width joiners have zero width.
chWidth = 0
}
}
runeSequence = append(runeSequence, ch)
runeSeqWidth += chWidth