diff --git a/pkg/tui/views/chat/input.go b/pkg/tui/views/chat/input.go index 4afab6b..0326915 100644 --- a/pkg/tui/views/chat/input.go +++ b/pkg/tui/views/chat/input.go @@ -53,6 +53,13 @@ func (m *Model) handleInput(msg tea.KeyMsg) tea.Cmd { return shared.KeyHandled(msg) case "ctrl+t": m.showDetails = !m.showDetails + if !m.showDetails && m.selectedMessage == 0 { + if len(m.App.Messages) > 1 { + m.selectedMessage = 1 + } else { + m.selectedMessage = -1 + } + } m.rebuildMessageCache() m.updateContent() return shared.KeyHandled(msg) @@ -157,6 +164,9 @@ func (m *Model) handleInputKey(msg tea.KeyMsg) tea.Cmd { } offset := m.messageOffsets[m.selectedMessage] tuiutil.ScrollIntoView(&m.content, offset, m.content.Height/2) + } else { + m.selectedMessage = -1 + m.content.GotoTop() } m.updateContent() m.input.Blur() diff --git a/pkg/tui/views/chat/update.go b/pkg/tui/views/chat/update.go index 61d15d5..871f1de 100644 --- a/pkg/tui/views/chat/update.go +++ b/pkg/tui/views/chat/update.go @@ -78,6 +78,12 @@ func (m *Model) Update(msg tea.Msg) (shared.ViewModel, tea.Cmd) { if m.App.Conversation.ID > 0 { // (re)load conversation contents cmds = append(cmds, m.loadConversationMessages()) + } else { + if len(m.App.Messages) > 0 && m.showDetails { + m.selectedMessage = 0 + } else { + m.selectedMessage = -1 + } } case tuiutil.MsgTempfileEditorClosed: contents := string(msg) @@ -97,11 +103,7 @@ func (m *Model) Update(msg tea.Msg) (shared.ViewModel, tea.Cmd) { } case msgConversationMessagesLoaded: m.App.Messages = msg.messages - if m.selectedMessage == -1 { - m.selectedMessage = len(msg.messages) - 1 - } else { - m.selectedMessage = min(m.selectedMessage, len(m.App.Messages)) - } + m.selectedMessage = len(msg.messages) - 1 m.rebuildMessageCache() m.updateContent() case msgChatResponseChunk: