Avoiding infinite loop on narrow TextViews. Fixes #333

This commit is contained in:
Oliver 2019-10-17 12:07:41 +02:00
parent de7ae86b5b
commit c35e6b2b4c
1 changed files with 8 additions and 0 deletions

View File

@ -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 {