Skip to content

Commit

Permalink
fix: Fix invalid order of event handling in input/text (#284)
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 authored Jul 22, 2024
1 parent c97dfad commit dad7190
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 @@ -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
Expand Down Expand Up @@ -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...)
}

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

Expand Down

0 comments on commit dad7190

Please sign in to comment.