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:
parent
b03a4607a4
commit
96a065d8ff
@ -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
19
views/text_test.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user