1
0
mirror of https://github.com/gdamore/tcell.git synced 2025-04-24 13:48:51 +08:00

Fixed text incorrect width calculation for multiline strings

This commit is contained in:
Anatoly Rugalev 2020-03-03 01:32:33 +03:00 committed by Garrett D'Amore
parent b03a4607a4
commit 96a065d8ff
2 changed files with 20 additions and 2 deletions

View File

@ -190,9 +190,8 @@ func (t *Text) SetText(s string) {
t.lengths = append(t.lengths, length) t.lengths = append(t.lengths, length)
if length > t.width { if length > t.width {
t.width = length t.width = length
length = 0
} }
length = 0
} else if t.widths[i] == 0 && length == 0 { } else if t.widths[i] == 0 && length == 0 {
// If first character on line is combining, inject // If first character on line is combining, inject
// a leading space. (Shame on the caller!) // a leading space. (Shame on the caller!)

19
views/text_test.go Normal file
View File

@ -0,0 +1,19 @@
package views
import "testing"
func TestText(t *testing.T) {
text := &Text{}
text.SetText(`
This
String
Is
Pretty
Long
12345678901234567890
`)
if text.width != 20 {
t.Errorf("Incorrect width: %d, expected: %d", text.width, 20)
}
}