on main help sign in
fix(ui): list: scroll to bottom after session load
a1648a8Ayman Bagabas
internal/ui/model/ui.go+12
@@ -177,6 +177,10 @@ func (m *UI) Init() tea.Cmd {
177 return tea.Batch(cmds...)
177 return tea.Batch(cmds...)
178}
178}
179
179
180+// sessionLoadedDoneMsg indicates that session loading and message appending is
181+// done.
182+type sessionLoadedDoneMsg struct{}
183+
180// Update handles updates to the UI model.
184// Update handles updates to the UI model.
181func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
185func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
182 var cmds []tea.Cmd
186 var cmds []tea.Cmd
@@ -194,7 +198,15 @@ func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
194 for _, message := range msgs {
198 for _, message := range msgs {
195 m.chat.AppendMessage(message)
199 m.chat.AppendMessage(message)
196 }
200 }
201+ // Notify that session loading is done to scroll to bottom. This is
202+ // needed because we need to draw the chat list first before we can
203+ // scroll to bottom.
204+ cmds = append(cmds, func() tea.Msg {
205+ return sessionLoadedDoneMsg{}
206+ })
207+ case sessionLoadedDoneMsg:
197 m.chat.ScrollToBottom()
208 m.chat.ScrollToBottom()
209+ m.chat.SelectLast()
198 case sessionFilesLoadedMsg:
210 case sessionFilesLoadedMsg:
199 m.sessionFiles = msg.files
211 m.sessionFiles = msg.files
200 case pubsub.Event[history.File]:
212 case pubsub.Event[history.File]: