Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion textarea/textarea.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ func (m Model) Value() string {
func (m *Model) Length() int {
var l int
for _, row := range m.value {
l += uniseg.StringWidth(string(row))
l += len(row)
}
// We add len(m.value) to include the newline characters.
return l + len(m.value) - 1
Expand Down
19 changes: 19 additions & 0 deletions textarea/textarea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2390,6 +2390,25 @@ func TestDynamicHeight_ShrinksWhenScrolledNoMaxContent(t *testing.T) {
}
}

func TestCharLimitWideRunes(t *testing.T) {
m := newTextArea()
m.Prompt = ""
m.ShowLineNumbers = false
m.CharLimit = 5

// Five East Asian wide runes, each two cells wide. CharLimit counts
// characters, not display cells, so all five should be accepted (this
// matches textinput, which limits by rune count).
m = sendString(m, "你好世界龍")

if got := len([]rune(m.Value())); got != 5 {
t.Errorf("CharLimit=5 admitted %d wide characters, want 5", got)
}
if got := m.Length(); got != 5 {
t.Errorf("Length() = %d for five characters, want 5", got)
}
}

func newTextArea() Model {
textarea := New()

Expand Down