diff --git a/textview.go b/textview.go index 0732ec4..115084d 100644 --- a/textview.go +++ b/textview.go @@ -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 diff --git a/util.go b/util.go index b738fb7..60d66e1 100644 --- a/util.go +++ b/util.go @@ -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