|
|
|
@ -4,6 +4,7 @@ import (
|
|
|
|
|
"bytes" |
|
|
|
|
"regexp" |
|
|
|
|
"sync" |
|
|
|
|
"unicode" |
|
|
|
|
"unicode/utf8" |
|
|
|
|
|
|
|
|
|
"github.com/gdamore/tcell/v2" |
|
|
|
@ -970,10 +971,10 @@ func (t *TextView) reindexBuffer(width int) {
|
|
|
|
|
if t.wrap && t.wordWrap { |
|
|
|
|
for _, line := range t.index { |
|
|
|
|
str := t.buffer[line.Line][line.Pos:line.NextPos] |
|
|
|
|
spaces := spacePattern.FindAllIndex(str, -1) |
|
|
|
|
if spaces != nil && spaces[len(spaces)-1][1] == len(str) { |
|
|
|
|
trimmed := bytes.TrimRightFunc(str, unicode.IsSpace) |
|
|
|
|
if len(trimmed) != len(str) { |
|
|
|
|
oldNextPos := line.NextPos |
|
|
|
|
line.NextPos -= spaces[len(spaces)-1][1] - spaces[len(spaces)-1][0] |
|
|
|
|
line.NextPos -= len(str) - len(trimmed) |
|
|
|
|
line.Width -= stringWidth(string(t.buffer[line.Line][line.NextPos:oldNextPos])) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|