From dad719087fe0db3f002e02328936e12b55733379 Mon Sep 17 00:00:00 2001 From: Sculas Date: Mon, 22 Jul 2024 19:15:56 +0200 Subject: [PATCH] fix: Fix invalid order of event handling in input/text (#284) Key binds should be checked before the key event is accepted as user input. See charmbracelet/bubbletea#1041 for more information. --- field_input.go | 8 ++++---- field_text.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/field_input.go b/field_input.go index fde27c84..6842c4f9 100644 --- a/field_input.go +++ b/field_input.go @@ -273,10 +273,6 @@ func (i *Input) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmds []tea.Cmd var cmd tea.Cmd - i.textinput, cmd = i.textinput.Update(msg) - cmds = append(cmds, cmd) - i.accessor.Set(i.textinput.Value()) - switch msg := msg.(type) { case updateFieldMsg: var cmds []tea.Cmd @@ -362,6 +358,10 @@ func (i *Input) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } } + i.textinput, cmd = i.textinput.Update(msg) + cmds = append(cmds, cmd) + i.accessor.Set(i.textinput.Value()) + return i, tea.Batch(cmds...) } diff --git a/field_text.go b/field_text.go index 22b77e07..7424a48e 100644 --- a/field_text.go +++ b/field_text.go @@ -253,10 +253,6 @@ func (t *Text) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmds []tea.Cmd var cmd tea.Cmd - t.textarea, cmd = t.textarea.Update(msg) - cmds = append(cmds, cmd) - t.accessor.Set(t.textarea.Value()) - switch msg := msg.(type) { case updateValueMsg: t.textarea.SetValue(string(msg)) @@ -338,6 +334,10 @@ func (t *Text) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } } + t.textarea, cmd = t.textarea.Update(msg) + cmds = append(cmds, cmd) + t.accessor.Set(t.textarea.Value()) + return t, tea.Batch(cmds...) }