mirror of https://github.com/rivo/tview.git
Avoiding infinite loop on narrow TextViews. Fixes #333
This commit is contained in:
parent
de7ae86b5b
commit
c35e6b2b4c
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
colorful "github.com/lucasb-eyer/go-colorful"
|
colorful "github.com/lucasb-eyer/go-colorful"
|
||||||
runewidth "github.com/mattn/go-runewidth"
|
runewidth "github.com/mattn/go-runewidth"
|
||||||
|
"github.com/rivo/uniseg"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -599,6 +600,13 @@ func (t *TextView) reindexBuffer(width int) {
|
||||||
if t.wrap && len(str) > 0 {
|
if t.wrap && len(str) > 0 {
|
||||||
for len(str) > 0 {
|
for len(str) > 0 {
|
||||||
extract := runewidth.Truncate(str, width, "")
|
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) {
|
if t.wordWrap && len(extract) < len(str) {
|
||||||
// Add any spaces from the next line.
|
// Add any spaces from the next line.
|
||||||
if spaces := spacePattern.FindStringIndex(str[len(extract):]); spaces != nil && spaces[0] == 0 {
|
if spaces := spacePattern.FindStringIndex(str[len(extract):]); spaces != nil && spaces[0] == 0 {
|
||||||
|
|
Loading…
Reference in New Issue