mirror of https://github.com/gdamore/tcell.git
Fix TextArea SetContent method
SetContent should overwrite the model, not append to it. Add a test to check model's width and height after SetContent calls.
This commit is contained in:
parent
1f1f979c1b
commit
e277d9c03b
|
@ -90,10 +90,11 @@ func (m *linesModel) GetCursor() (int, int, bool, bool) {
|
|||
func (ta *TextArea) SetLines(lines []string) {
|
||||
ta.Init()
|
||||
m := ta.model
|
||||
m.width =0
|
||||
|
||||
// extend slice before using m.runes[row] to avoid panic
|
||||
slice := make([][]rune, len(lines))
|
||||
m.runes = append(m.runes, slice...)
|
||||
m.runes = slice
|
||||
|
||||
for row, line := range lines {
|
||||
for _, ch := range line {
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package views
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSetContent(t *testing.T) {
|
||||
ta := &TextArea{}
|
||||
|
||||
ta.SetContent("This is a quite long line.") // This line is longer than 11.
|
||||
ta.SetContent("Four.\nFive...\n...and Six.") //"...and Six." should be 11 long.
|
||||
|
||||
if ta.model.height != 3 {
|
||||
t.Errorf("Incorrect height: %d, expected: %d", ta.model.height, 3)
|
||||
}
|
||||
if ta.model.width != 11 {
|
||||
t.Errorf("Incorrect width: %d, expected: %d", ta.model.width, 11)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue