From a4dc540f3d4c0684d7f83c878218a44302185f72 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Wed, 19 Jan 2022 20:53:10 -0500 Subject: [PATCH] Re-add panic guard in deleteWordLeft in textinput, just in case --- textinput/textinput.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/textinput/textinput.go b/textinput/textinput.go index 3f20e6c..3ecb3f4 100644 --- a/textinput/textinput.go +++ b/textinput/textinput.go @@ -412,7 +412,11 @@ func (m *Model) deleteWordLeft() bool { return m.deleteBeforeCursor() } - oldPos := m.pos + // Linter note: it's critical that we acquire the initial cursor position + // here prior to altering it via SetCursor() below. As such, moving this + // call into the corresponding if clause does not apply here. + oldPos := m.pos //nolint:ifshort + blink := m.setCursor(m.pos - 1) for unicode.IsSpace(m.value[m.pos]) { if m.pos <= 0 { @@ -434,7 +438,11 @@ func (m *Model) deleteWordLeft() bool { } } - m.value = append(m.value[:m.pos], m.value[oldPos:]...) + if oldPos > len(m.value) { + m.value = m.value[:m.pos] + } else { + m.value = append(m.value[:m.pos], m.value[oldPos:]...) + } return blink }