From 151d1026ddbac682d6f7f9b59cce3421cc9cd224 Mon Sep 17 00:00:00 2001 From: IllusionMan1212 Date: Thu, 20 Jan 2022 01:10:58 +0200 Subject: [PATCH] fix(textinput): use old cursor pos and simplify logic --- textinput/textinput.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/textinput/textinput.go b/textinput/textinput.go index 31141fc..3f20e6c 100644 --- a/textinput/textinput.go +++ b/textinput/textinput.go @@ -412,6 +412,7 @@ func (m *Model) deleteWordLeft() bool { return m.deleteBeforeCursor() } + oldPos := m.pos blink := m.setCursor(m.pos - 1) for unicode.IsSpace(m.value[m.pos]) { if m.pos <= 0 { @@ -433,11 +434,7 @@ func (m *Model) deleteWordLeft() bool { } } - if m.pos > len(m.value) { - m.value = m.value[:m.pos] - } else { - m.value = append(m.value[:m.pos], m.value[m.pos:]...) - } + m.value = append(m.value[:m.pos], m.value[oldPos:]...) return blink }