diff --git a/textview.go b/textview.go index ddad69d..0732ec4 100644 --- a/textview.go +++ b/textview.go @@ -883,8 +883,12 @@ func (t *TextView) Draw(screen tcell.Screen) { comb = make([]rune, len(runeSequence)-1) copy(comb, runeSequence[1:]) } - for offset := 0; offset < runeSeqWidth; offset++ { - screen.SetContent(x+posX+offset, y+line-t.lineOffset, runeSequence[0], comb, style) + for offset := runeSeqWidth - 1; offset >= 0; offset-- { + if offset == 0 { + screen.SetContent(x+posX+offset, y+line-t.lineOffset, runeSequence[0], comb, style) + } else { + screen.SetContent(x+posX+offset, y+line-t.lineOffset, ' ', nil, style) + } } // Advance. @@ -926,14 +930,18 @@ func (t *TextView) Draw(screen tcell.Screen) { // Determine the width of this rune. chWidth := runewidth.RuneWidth(ch) if chWidth == 0 { - // If this is not a modifier, we treat it as a space character. if len(runeSequence) == 0 { + // If this is not a modifier, we treat it as a space character. ch = ' ' chWidth = 1 } else { runeSequence = append(runeSequence, ch) continue } + } else if runeSequence[len(runeSequence)-1] == '\u200d' { + // Keep collecting if the previous character was a zero-width joiner. + runeSequence = append(runeSequence, ch) + continue } // Skip to the right. diff --git a/util.go b/util.go index 44c8057..b738fb7 100644 --- a/util.go +++ b/util.go @@ -321,7 +321,7 @@ func printWithStyle(screen tcell.Screen, text string, x, y, maxWidth, align int, colorPos, escapePos int foregroundColor, backgroundColor, attributes string ) - runeSequence := make([]rune, 0, 10) + runeSequence := make([]rune, 0, 20) runeSeqWidth := 0 flush := func() { if len(runeSequence) == 0 { @@ -339,9 +339,13 @@ func printWithStyle(screen tcell.Screen, text string, x, y, maxWidth, align int, comb = make([]rune, len(runeSequence)-1) copy(comb, runeSequence[1:]) } - for offset := 0; offset < runeSeqWidth; offset++ { + for offset := runeSeqWidth - 1; offset >= 0; offset-- { // To avoid undesired effects, we place the same character in all cells. - screen.SetContent(finalX+offset, y, runeSequence[0], comb, finalStyle) + if offset == 0 { + screen.SetContent(finalX+offset, y, runeSequence[0], comb, finalStyle) + } else { + screen.SetContent(finalX+offset, y, ' ', nil, finalStyle) + } } // Advance and reset. @@ -384,8 +388,9 @@ func printWithStyle(screen tcell.Screen, text string, x, y, maxWidth, align int, ch = ' ' chWidth = 1 } - } else { - // We have a character. Flush all previous runes. + } 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() } runeSequence = append(runeSequence, ch)