on main help sign in
feat(tui): chat: clear selection on esc
f0377a3Ayman Bagabas
internal/tui/components/chat/chat.go+7−2
@@ -96,8 +96,13 @@ func (m *messageListCmp) Init() tea.Cmd {
96func (m *messageListCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
96func (m *messageListCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
97 switch msg := msg.(type) {
97 switch msg := msg.(type) {
98 case tea.KeyPressMsg:
98 case tea.KeyPressMsg:
99− if key.Matches(msg, messages.CopyKey) && m.listCmp.HasSelection() {
99+ if m.listCmp.IsFocused() && m.listCmp.HasSelection() {
100+ switch {
101+ case key.Matches(msg, messages.CopyKey):
100− return m, m.CopySelectedText(true)
102+ return m, m.CopySelectedText(true)
103+ case key.Matches(msg, messages.ClearSelectionKey):
104+ return m, m.SelectionClear()
105+ }
101 }
106 }
102 case tea.MouseClickMsg:
107 case tea.MouseClickMsg:
103 x := msg.X - 1 // Adjust for padding
108 x := msg.X - 1 // Adjust for padding
internal/tui/components/chat/messages/messages.go+3
@@ -28,6 +28,9 @@ import (
28// CopyKey is the key binding for copying message content to the clipboard.
28// CopyKey is the key binding for copying message content to the clipboard.
29var CopyKey = key.NewBinding(key.WithKeys("c", "y", "C", "Y"), key.WithHelp("c/y", "copy"))
29var CopyKey = key.NewBinding(key.WithKeys("c", "y", "C", "Y"), key.WithHelp("c/y", "copy"))
30
30
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+
31// MessageCmp defines the interface for message components in the chat interface.
34// MessageCmp defines the interface for message components in the chat interface.
32// It combines standard UI model interfaces with message-specific functionality.
35// It combines standard UI model interfaces with message-specific functionality.
33type MessageCmp interface {
36type MessageCmp interface {