Updates/fixes to selectedMessage handling in chat TUI view

This commit is contained in:
Matt Low 2024-12-11 15:54:57 +00:00
parent 1996300c40
commit c261fdadf5
2 changed files with 17 additions and 5 deletions

View File

@ -53,6 +53,13 @@ func (m *Model) handleInput(msg tea.KeyMsg) tea.Cmd {
return shared.KeyHandled(msg) return shared.KeyHandled(msg)
case "ctrl+t": case "ctrl+t":
m.showDetails = !m.showDetails 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.rebuildMessageCache()
m.updateContent() m.updateContent()
return shared.KeyHandled(msg) return shared.KeyHandled(msg)
@ -157,6 +164,9 @@ func (m *Model) handleInputKey(msg tea.KeyMsg) tea.Cmd {
} }
offset := m.messageOffsets[m.selectedMessage] offset := m.messageOffsets[m.selectedMessage]
tuiutil.ScrollIntoView(&m.content, offset, m.content.Height/2) tuiutil.ScrollIntoView(&m.content, offset, m.content.Height/2)
} else {
m.selectedMessage = -1
m.content.GotoTop()
} }
m.updateContent() m.updateContent()
m.input.Blur() m.input.Blur()

View File

@ -78,6 +78,12 @@ func (m *Model) Update(msg tea.Msg) (shared.ViewModel, tea.Cmd) {
if m.App.Conversation.ID > 0 { if m.App.Conversation.ID > 0 {
// (re)load conversation contents // (re)load conversation contents
cmds = append(cmds, m.loadConversationMessages()) cmds = append(cmds, m.loadConversationMessages())
} else {
if len(m.App.Messages) > 0 && m.showDetails {
m.selectedMessage = 0
} else {
m.selectedMessage = -1
}
} }
case tuiutil.MsgTempfileEditorClosed: case tuiutil.MsgTempfileEditorClosed:
contents := string(msg) contents := string(msg)
@ -97,11 +103,7 @@ func (m *Model) Update(msg tea.Msg) (shared.ViewModel, tea.Cmd) {
} }
case msgConversationMessagesLoaded: case msgConversationMessagesLoaded:
m.App.Messages = msg.messages m.App.Messages = msg.messages
if m.selectedMessage == -1 {
m.selectedMessage = len(msg.messages) - 1 m.selectedMessage = len(msg.messages) - 1
} else {
m.selectedMessage = min(m.selectedMessage, len(m.App.Messages))
}
m.rebuildMessageCache() m.rebuildMessageCache()
m.updateContent() m.updateContent()
case msgChatResponseChunk: case msgChatResponseChunk: