From b95057c3f8501ace6272d50caa4acd1947b425d9 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 f355bbae..41187365 100644 --- a/textinput/textinput.go +++ b/textinput/textinput.go @@ -410,6 +410,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) } @@ -452,6 +455,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) {