From 6b545747ded24028e506ec8442eff1315bb6c231 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 5 Aug 2025 16:24:30 -0400 Subject: [PATCH] fix(chat): expose copy key binding --- internal/tui/components/chat/messages/messages.go | 5 +++-- internal/tui/components/chat/messages/tool.go | 2 +- internal/tui/page/chat/chat.go | 6 ++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/internal/tui/components/chat/messages/messages.go b/internal/tui/components/chat/messages/messages.go index b1a17eee4e4b91885941deb415cf8c9fd877fe72..891f4e483fcc7b9cdb6d82485998329995d542a6 100644 --- a/internal/tui/components/chat/messages/messages.go +++ b/internal/tui/components/chat/messages/messages.go @@ -25,7 +25,8 @@ import ( "github.com/charmbracelet/crush/internal/tui/util" ) -var copyKey = key.NewBinding(key.WithKeys("c", "y", "C", "Y"), key.WithHelp("c/y", "copy")) +// 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")) // MessageCmp defines the interface for message components in the chat interface. // It combines standard UI model interfaces with message-specific functionality. @@ -99,7 +100,7 @@ func (m *messageCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, cmd } case tea.KeyPressMsg: - if key.Matches(msg, copyKey) { + if key.Matches(msg, CopyKey) { err := clipboard.WriteAll(m.message.Content().Text) if err != nil { return m, util.ReportError(fmt.Errorf("failed to copy message content to clipboard: %w", err)) diff --git a/internal/tui/components/chat/messages/tool.go b/internal/tui/components/chat/messages/tool.go index 7708b6b3e273471973a355bc77c0110c0be21e45..41bb7b81d0e9fa202e98bd91aca4f2eddf9c22c1 100644 --- a/internal/tui/components/chat/messages/tool.go +++ b/internal/tui/components/chat/messages/tool.go @@ -165,7 +165,7 @@ func (m *toolCallCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } return m, tea.Batch(cmds...) case tea.KeyPressMsg: - if key.Matches(msg, copyKey) { + if key.Matches(msg, CopyKey) { return m, m.copyTool() } } diff --git a/internal/tui/page/chat/chat.go b/internal/tui/page/chat/chat.go index a281ef0b0ae80ffd4ad07d7d16a8755b782bf0b6..0276ab2a917bf9225d381b483f403d064fefe39a 100644 --- a/internal/tui/page/chat/chat.go +++ b/internal/tui/page/chat/chat.go @@ -19,6 +19,7 @@ import ( "github.com/charmbracelet/crush/internal/tui/components/chat" "github.com/charmbracelet/crush/internal/tui/components/chat/editor" "github.com/charmbracelet/crush/internal/tui/components/chat/header" + "github.com/charmbracelet/crush/internal/tui/components/chat/messages" "github.com/charmbracelet/crush/internal/tui/components/chat/sidebar" "github.com/charmbracelet/crush/internal/tui/components/chat/splash" "github.com/charmbracelet/crush/internal/tui/components/completions" @@ -865,10 +866,7 @@ func (p *chatPage) Help() help.KeyMap { key.WithKeys("up", "down"), key.WithHelp("↑↓", "scroll"), ), - key.NewBinding( - key.WithKeys("c", "y"), - key.WithHelp("c/y", "copy"), - ), + messages.CopyKey, ) fullList = append(fullList, []key.Binding{