From c426cb580bf6de0c84224e03fdaae06d39e3d9eb Mon Sep 17 00:00:00 2001 From: IllusionMan1212 Date: Fri, 31 Dec 2021 17:33:55 +0200 Subject: [PATCH] fix textinput infinite loop and panic 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() --- textinput/textinput.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/textinput/textinput.go b/textinput/textinput.go index ba5c7721..6f3481ed 100644 --- a/textinput/textinput.go +++ b/textinput/textinput.go @@ -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) } @@ -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) {