Skip to content

Commit

Permalink
refactor(textinput): Do not need to return err as well as set m.Err
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani committed Jun 10, 2022
1 parent f9749f5 commit ad414d7
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions textinput/textinput.go
Expand Up @@ -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
}
}

Expand All @@ -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.
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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))
}
}
Expand Down

0 comments on commit ad414d7

Please sign in to comment.