Skip to content

Commit

Permalink
fix: change name
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani committed Mar 13, 2024
1 parent e7b3760 commit 7f0383b
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions textinput/textinput.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (m *Model) SetValue(s string) {
// Clean up any special characters in the input provided by the
// caller. This avoids bugs due to e.g. tab characters and whatnot.
runes := m.san().Sanitize([]rune(s))
err := m.validateIfDefined(string(runes))
err := m.validate(runes)
m.setValueInternal(runes, err)
}

Expand Down Expand Up @@ -316,7 +316,7 @@ func (m *Model) insertRunesFromUserInput(v []rune) {

// Put it all back together
value := append(head, tail...)
inputErr := m.validateIfDefined(string(value))
inputErr := m.validate(value)
m.setValueInternal(value, inputErr)
}

Expand Down Expand Up @@ -368,7 +368,7 @@ func (m *Model) handleOverflow() {
// deleteBeforeCursor deletes all text before the cursor.
func (m *Model) deleteBeforeCursor() {
m.value = m.value[m.pos:]
m.Err = m.validateIfDefined(string(m.value))
m.Err = m.validate(m.value)
m.offset = 0
m.SetCursor(0)
}
Expand All @@ -378,7 +378,7 @@ func (m *Model) deleteBeforeCursor() {
// masked input.
func (m *Model) deleteAfterCursor() {
m.value = m.value[:m.pos]
m.Err = m.validateIfDefined(string(m.value))
m.Err = m.validate(m.value)
m.SetCursor(len(m.value))
}

Expand Down Expand Up @@ -424,7 +424,7 @@ func (m *Model) deleteWordBackward() {
} else {
m.value = append(m.value[:m.pos], m.value[oldPos:]...)
}
m.Err = m.validateIfDefined(string(m.value))
m.Err = m.validate(m.value)
}

// deleteWordForward deletes the word right to the cursor. If input is masked
Expand Down Expand Up @@ -464,7 +464,7 @@ func (m *Model) deleteWordForward() {
} else {
m.value = append(m.value[:oldPos], m.value[m.pos:]...)
}
m.Err = m.validateIfDefined(string(m.value))
m.Err = m.validate(m.value)

m.SetCursor(oldPos)
}
Expand Down Expand Up @@ -574,7 +574,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
m.Err = nil
if len(m.value) > 0 {
m.value = append(m.value[:max(0, m.pos-1)], m.value[m.pos:]...)
m.Err = m.validateIfDefined(string(m.value))
m.Err = m.validate(m.value)
if m.pos > 0 {
m.SetCursor(m.pos - 1)
}
Expand All @@ -596,7 +596,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
case key.Matches(msg, m.KeyMap.DeleteCharacterForward):
if len(m.value) > 0 && m.pos < len(m.value) {
m.value = append(m.value[:m.pos], m.value[m.pos+1:]...)
m.Err = m.validateIfDefined(string(m.value))
m.Err = m.validate(m.value)
}
case key.Matches(msg, m.KeyMap.LineEnd):
m.CursorEnd()
Expand Down Expand Up @@ -878,9 +878,9 @@ func (m *Model) previousSuggestion() {
}
}

func (m Model) validateIfDefined(v string) error {
func (m Model) validate(v []rune) error {
if m.Validate != nil {
return m.Validate(v)
return m.Validate(string(v))
}
return nil
}

0 comments on commit 7f0383b

Please sign in to comment.