diff --git a/textview.go b/textview.go index 82b878f..6430a93 100644 --- a/textview.go +++ b/textview.go @@ -11,6 +11,7 @@ import ( "github.com/gdamore/tcell" colorful "github.com/lucasb-eyer/go-colorful" runewidth "github.com/mattn/go-runewidth" + "github.com/rivo/uniseg" ) var ( @@ -599,6 +600,13 @@ func (t *TextView) reindexBuffer(width int) { if t.wrap && len(str) > 0 { for len(str) > 0 { extract := runewidth.Truncate(str, width, "") + if len(extract) == 0 { + // We'll extract at least one grapheme cluster. + gr := uniseg.NewGraphemes(str) + gr.Next() + _, to := gr.Positions() + extract = str[:to] + } if t.wordWrap && len(extract) < len(str) { // Add any spaces from the next line. if spaces := spacePattern.FindStringIndex(str[len(extract):]); spaces != nil && spaces[0] == 0 {