diff --git a/textarea/textarea.go b/textarea/textarea.go index f0c0ca54b..af862f1e9 100644 --- a/textarea/textarea.go +++ b/textarea/textarea.go @@ -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 diff --git a/textarea/textarea_test.go b/textarea/textarea_test.go index 41d51f744..e7fb7b459 100644 --- a/textarea/textarea_test.go +++ b/textarea/textarea_test.go @@ -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()