From 923390de7aec1d0b067e8784a0e64817f397ce88 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Fri, 17 Jan 2020 22:28:17 -0500 Subject: [PATCH] Fix index out of range error when using backspace --- input/input.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/input/input.go b/input/input.go index 31b71f8..cb39e56 100644 --- a/input/input.go +++ b/input/input.go @@ -1,7 +1,6 @@ package input import ( - "log" "tea" "time" ) @@ -31,13 +30,14 @@ func DefaultModel() Model { func Update(msg tea.Msg, model tea.Model) (Model, tea.Cmd) { m, _ := model.(Model) - log.Printf("msg: %v\n", msg) switch msg := msg.(type) { case tea.KeyMsg: switch msg.Type { case tea.KeyBackspace: - m.Value = m.Value[:len(m.Value)-1] + if len(m.Value) > 0 { + m.Value = m.Value[:len(m.Value)-1] + } case tea.KeyRune: m.Value = m.Value + msg.String() }