diff --git a/internal/tui/components/chat/chat.go b/internal/tui/components/chat/chat.go index 22ef7099b505977432c650655ec9a30c098f85dd..00e18135b5d498c08c7db52135691f5db61ce220 100644 --- a/internal/tui/components/chat/chat.go +++ b/internal/tui/components/chat/chat.go @@ -96,8 +96,13 @@ func (m *messageListCmp) Init() tea.Cmd { func (m *messageListCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: - if key.Matches(msg, messages.CopyKey) && m.listCmp.HasSelection() { - return m, m.CopySelectedText(true) + if m.listCmp.IsFocused() && m.listCmp.HasSelection() { + switch { + case key.Matches(msg, messages.CopyKey): + return m, m.CopySelectedText(true) + case key.Matches(msg, messages.ClearSelectionKey): + return m, m.SelectionClear() + } } case tea.MouseClickMsg: x := msg.X - 1 // Adjust for padding diff --git a/internal/tui/components/chat/messages/messages.go b/internal/tui/components/chat/messages/messages.go index bc594ab5e1240ff004bdb9548afa872ac1bb62e8..ec55800aab85a2dbb07153c12300dbad892b3b6a 100644 --- a/internal/tui/components/chat/messages/messages.go +++ b/internal/tui/components/chat/messages/messages.go @@ -28,6 +28,9 @@ import ( // CopyKey is the key binding for copying message content to the clipboard. var CopyKey = key.NewBinding(key.WithKeys("c", "y", "C", "Y"), key.WithHelp("c/y", "copy")) +// ClearSelectionKey is the key binding for clearing the current selection in the chat interface. +var ClearSelectionKey = key.NewBinding(key.WithKeys("esc"), key.WithHelp("esc", "clear selection")) + // MessageCmp defines the interface for message components in the chat interface. // It combines standard UI model interfaces with message-specific functionality. type MessageCmp interface {