on main help sign in
feat(tui): chat: clear selection on esc
commitf0377a3a862f9c4ffffa112f137ca28989b108bf authorAyman Bagabas <ayman.bagabas@gmail.com> dateWed 6 Aug 2025, 14:56 (1 year ago) parent2e30226
2 files changed+10−2
internal/tui/components/chat/chat.go+7−2 internal/tui/components/chat/messages/messages.go+3
internal/tui/components/chat/chat.go+7−2
@@ -96,8 +96,13 @@ func (m *messageListCmp) Init() tea.Cmd {
9696func (m *messageListCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
9797 switch msg := msg.(type) {
9898 case tea.KeyPressMsg:
99− if key.Matches(msg, messages.CopyKey) && m.listCmp.HasSelection() {
100− return m, m.CopySelectedText(true)
99+ if m.listCmp.IsFocused() && m.listCmp.HasSelection() {
100+ switch {
101+ case key.Matches(msg, messages.CopyKey):
102+ return m, m.CopySelectedText(true)
103+ case key.Matches(msg, messages.ClearSelectionKey):
104+ return m, m.SelectionClear()
105+ }
101106 }
102107 case tea.MouseClickMsg:
103108 x := msg.X - 1 // Adjust for padding
internal/tui/components/chat/messages/messages.go+3
@@ -28,6 +28,9 @@ import (
2828// CopyKey is the key binding for copying message content to the clipboard.
2929var CopyKey = key.NewBinding(key.WithKeys("c", "y", "C", "Y"), key.WithHelp("c/y", "copy"))
3030
31+// ClearSelectionKey is the key binding for clearing the current selection in the chat interface.
32+var ClearSelectionKey = key.NewBinding(key.WithKeys("esc"), key.WithHelp("esc", "clear selection"))
33+
3134// MessageCmp defines the interface for message components in the chat interface.
3235// It combines standard UI model interfaces with message-specific functionality.
3336type MessageCmp interface {