Skip to content

Commit

Permalink
fix: Fix invalid order of event handling in input/text
Browse files Browse the repository at this point in the history
Key binds should be checked before the key event is accepted as user input. See charmbracelet/bubbletea#1041 for more information.
  • Loading branch information
Sculas committed Jun 18, 2024
1 parent 90406d7 commit 596c6e9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions field_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,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 tea.KeyMsg:
i.err = nil
Expand All @@ -231,6 +227,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...)
}

Expand Down
8 changes: 4 additions & 4 deletions field_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,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))
Expand Down Expand Up @@ -244,6 +240,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...)
}

Expand Down

0 comments on commit 596c6e9

Please sign in to comment.