diff --git a/examples/chat/main.go b/examples/chat/main.go index 6b03a64582..d478870bbe 100644 --- a/examples/chat/main.go +++ b/examples/chat/main.go @@ -77,9 +77,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { vpCmd tea.Cmd ) - m.textarea, tiCmd = m.textarea.Update(msg) - m.viewport, vpCmd = m.viewport.Update(msg) - switch msg := msg.(type) { case tea.WindowSizeMsg: m.viewport.Width = msg.Width @@ -91,7 +88,11 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.viewport.SetContent(lipgloss.NewStyle().Width(m.viewport.Width).Render(strings.Join(m.messages, "\n"))) } m.viewport.GotoBottom() + m.textarea, tiCmd = m.textarea.Update(msg) + m.viewport, vpCmd = m.viewport.Update(msg) case tea.KeyMsg: + m.textarea, tiCmd = m.textarea.Update(msg) + m.viewport, vpCmd = m.viewport.Update(msg) switch msg.Type { case tea.KeyCtrlC, tea.KeyEsc: fmt.Println(m.textarea.Value()) @@ -107,6 +108,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case errMsg: m.err = msg return m, nil + + default: + m.textarea, tiCmd = m.textarea.Update(msg) + m.viewport, vpCmd = m.viewport.Update(msg) } return m, tea.Batch(tiCmd, vpCmd)