From ad414d781de794f761d0d99c9acfcd47b05cba61 Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Wed, 8 Jun 2022 13:44:07 -0400 Subject: [PATCH] refactor(textinput): Do not need to return err as well as set m.Err --- textinput/textinput.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/textinput/textinput.go b/textinput/textinput.go index c600a9b8..022e0378 100644 --- a/textinput/textinput.go +++ b/textinput/textinput.go @@ -188,12 +188,11 @@ func New() Model { var NewModel = New // SetValue sets the value of the text input. -// Returns an error if validation fails. -func (m *Model) SetValue(s string) error { +func (m *Model) SetValue(s string) { if m.Validate != nil { if err := m.Validate(s); err != nil { m.Err = err - return err + return } } @@ -209,8 +208,6 @@ func (m *Model) SetValue(s string) error { m.setCursor(len(m.value)) } m.handleOverflow() - - return nil } // Value returns the value of the text input. @@ -362,9 +359,9 @@ func (m *Model) handlePaste(v string) bool { // Put it all back together value := append(head, tail...) - err := m.SetValue(string(value)) + m.SetValue(string(value)) - if err != nil { + if m.Err != nil { m.pos = oldPos } @@ -681,8 +678,8 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { value := make([]rune, len(m.value)) copy(value, m.value) value = append(value[:m.pos], append(runes, value[m.pos:]...)...) - err := m.SetValue(string(value)) - if err == nil { + m.SetValue(string(value)) + if m.Err == nil { resetBlink = m.setCursor(m.pos + len(runes)) } }