diff --git a/internal/ui/model/ui.go b/internal/ui/model/ui.go index 50521afc211d17435ae03370e2c3008e8f74b196..22eac673a41e76874b9d9f04e31d313eb1fb09fa 100644 --- a/internal/ui/model/ui.go +++ b/internal/ui/model/ui.go @@ -177,6 +177,10 @@ func (m *UI) Init() tea.Cmd { return tea.Batch(cmds...) } +// sessionLoadedDoneMsg indicates that session loading and message appending is +// done. +type sessionLoadedDoneMsg struct{} + // Update handles updates to the UI model. func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmds []tea.Cmd @@ -194,7 +198,15 @@ func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { for _, message := range msgs { m.chat.AppendMessage(message) } + // Notify that session loading is done to scroll to bottom. This is + // needed because we need to draw the chat list first before we can + // scroll to bottom. + cmds = append(cmds, func() tea.Msg { + return sessionLoadedDoneMsg{} + }) + case sessionLoadedDoneMsg: m.chat.ScrollToBottom() + m.chat.SelectLast() case sessionFilesLoadedMsg: m.sessionFiles = msg.files case pubsub.Event[history.File]: