Skip to content

Commit

Permalink
fix textinput infinite loop and panic
Browse files Browse the repository at this point in the history
fixes infinite loop when deleting input that only contains whitespace
using deleteWordLeft()
fixes index out of range panic when deleting input that only contains
whitespace using deleteWordRight()
  • Loading branch information
IllusionMan1212 authored and meowgorithm committed Jan 11, 2022
1 parent 48e3f85 commit c426cb5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions textinput/textinput.go
Expand Up @@ -415,6 +415,9 @@ func (m *Model) deleteWordLeft() bool {
i := m.pos
blink := m.setCursor(m.pos - 1)
for unicode.IsSpace(m.value[m.pos]) {
if m.pos <= 0 {
break
}
// ignore series of whitespace before cursor
blink = m.setCursor(m.pos - 1)
}
Expand Down Expand Up @@ -457,6 +460,10 @@ func (m *Model) deleteWordRight() bool {
for unicode.IsSpace(m.value[m.pos]) {
// ignore series of whitespace after cursor
m.setCursor(m.pos + 1)

if m.pos >= len(m.value) {
break
}
}

for m.pos < len(m.value) {
Expand Down

0 comments on commit c426cb5

Please sign in to comment.