on main help sign in
Merge pull request #577 from charmbracelet/list-select-pp

Copy selected text

commit77ac083bfd7925a597ad66890672afdb42f4d4f2 authorKujtim Hoxha <kujtimii.h@gmail.com> dateWed 6 Aug 2025, 09:44 (1 year ago) parentebd68ac567b778
11 files changed+177−149
go.mod+5−5 go.sum+10−10 internal/tui/components/chat/chat.go+46−19 internal/tui/components/chat/messages/messages.go+11−7 internal/tui/components/chat/messages/tool.go+9−6 internal/tui/components/dialogs/permissions/keys.go+1−1 internal/tui/components/mcp/mcp.go+1−1 internal/tui/exp/list/list.go+69−87 internal/tui/page/chat/chat.go+11−5 internal/tui/styles/crush.go → internal/tui/styles/charmtone.go+5−2 internal/tui/styles/theme.go+9−6
go.mod+5−5
@@ -10,16 +10,16 @@ require (
1010 github.com/anthropics/anthropic-sdk-go v1.6.2
1111 github.com/atotto/clipboard v0.1.4
1212 github.com/aymanbagabas/go-udiff v0.3.1
13− github.com/bmatcuk/doublestar/v4 v4.9.0
13+ github.com/bmatcuk/doublestar/v4 v4.9.1
1414 github.com/charlievieth/fastwalk v1.0.11
1515 github.com/charmbracelet/bubbles/v2 v2.0.0-beta.1.0.20250716191546-1e2ffbbcf5c5
16− github.com/charmbracelet/bubbletea/v2 v2.0.0-beta.4.0.20250730165737-56ff7146d52d
17− github.com/charmbracelet/catwalk v0.4.5
16+ github.com/charmbracelet/bubbletea/v2 v2.0.0-beta.4.0.20250805190305-70e94a2e0b2d
17+ github.com/charmbracelet/catwalk v0.4.6
1818 github.com/charmbracelet/fang v0.3.1-0.20250711140230-d5ebb8c1d674
1919 github.com/charmbracelet/glamour/v2 v2.0.0-20250516160903-6f1e2c8f9ebe
2020 github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.3.0.20250721205738-ea66aa652ee0
2121 github.com/charmbracelet/log/v2 v2.0.0-20250226163916-c379e29ff706
22− github.com/charmbracelet/x/ansi v0.9.3
22+ github.com/charmbracelet/x/ansi v0.10.0
2323 github.com/charmbracelet/x/exp/charmtone v0.0.0-20250708181618-a60a724ba6c3
2424 github.com/charmbracelet/x/exp/golden v0.0.0-20250207160936-21c02780d27a
2525 github.com/disintegration/imageorient v0.0.0-20180920195336-8147d86e83ec
@@ -75,7 +75,7 @@ require (
7575 github.com/bahlo/generic-list-go v0.2.0 // indirect
7676 github.com/buger/jsonparser v1.1.1 // indirect
7777 github.com/charmbracelet/colorprofile v0.3.1 // indirect
78− github.com/charmbracelet/ultraviolet v0.0.0-20250731212901-76da584cc9a5
78+ github.com/charmbracelet/ultraviolet v0.0.0-20250805154935-01be9d7ef65d
7979 github.com/charmbracelet/x/cellbuf v0.0.14-0.20250516160309-24eee56f89fa // indirect
8080 github.com/charmbracelet/x/exp/slice v0.0.0-20250611152503-f53cdd7e01ef
8181 github.com/charmbracelet/x/term v0.2.1
go.sum+10−10
@@ -68,18 +68,18 @@ github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuP
6868github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
6969github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
7070github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
71−github.com/bmatcuk/doublestar/v4 v4.9.0 h1:DBvuZxjdKkRP/dr4GVV4w2fnmrk5Hxc90T51LZjv0JA=
72−github.com/bmatcuk/doublestar/v4 v4.9.0/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
71+github.com/bmatcuk/doublestar/v4 v4.9.1 h1:X8jg9rRZmJd4yRy7ZeNDRnM+T3ZfHv15JiBJ/avrEXE=
72+github.com/bmatcuk/doublestar/v4 v4.9.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
7373github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
7474github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
7575github.com/charlievieth/fastwalk v1.0.11 h1:5sLT/q9+d9xMdpKExawLppqvXFZCVKf6JHnr2u/ufj8=
7676github.com/charlievieth/fastwalk v1.0.11/go.mod h1:yGy1zbxog41ZVMcKA/i8ojXLFsuayX5VvwhQVoj9PBI=
7777github.com/charmbracelet/bubbles/v2 v2.0.0-beta.1.0.20250716191546-1e2ffbbcf5c5 h1:GTcMIfDQJKyNKS+xVt7GkNIwz+tBuQtIuiP50WpzNgs=
7878github.com/charmbracelet/bubbles/v2 v2.0.0-beta.1.0.20250716191546-1e2ffbbcf5c5/go.mod h1:6HamsBKWqEC/FVHuQMHgQL+knPyvHH55HwJDHl/adMw=
79−github.com/charmbracelet/bubbletea/v2 v2.0.0-beta.4.0.20250730165737-56ff7146d52d h1:YMXLZHSo8DjytVY/b5dK8LDuyQsVUmBK3ydQMpu2Ui4=
80−github.com/charmbracelet/bubbletea/v2 v2.0.0-beta.4.0.20250730165737-56ff7146d52d/go.mod h1:XIQ1qQfRph6Z5o2EikCydjumo0oDInQySRHuPATzbZc=
81−github.com/charmbracelet/catwalk v0.4.5 h1:Kv3PadDe8IF8gpcYTfAJdCee5Bv4HufvtNT61FXtq5g=
82−github.com/charmbracelet/catwalk v0.4.5/go.mod h1:WnKgNPmQHuMyk7GtwAQwl+ezHusfH40IvzML2qwUGwc=
79+github.com/charmbracelet/bubbletea/v2 v2.0.0-beta.4.0.20250805190305-70e94a2e0b2d h1:1C2whi5rgs+APtsQDE4riA+W5neYaMNY+Y+5o6J/rDU=
80+github.com/charmbracelet/bubbletea/v2 v2.0.0-beta.4.0.20250805190305-70e94a2e0b2d/go.mod h1:XIQ1qQfRph6Z5o2EikCydjumo0oDInQySRHuPATzbZc=
81+github.com/charmbracelet/catwalk v0.4.6 h1:Y0JDq5V4agK8oO3lKC/hhInrYXePGwZPNo8I1Lk08jc=
82+github.com/charmbracelet/catwalk v0.4.6/go.mod h1:WnKgNPmQHuMyk7GtwAQwl+ezHusfH40IvzML2qwUGwc=
8383github.com/charmbracelet/colorprofile v0.3.1 h1:k8dTHMd7fgw4bnFd7jXTLZrSU/CQrKnL3m+AxCzDz40=
8484github.com/charmbracelet/colorprofile v0.3.1/go.mod h1:/GkGusxNs8VB/RSOh3fu0TJmQ4ICMMPApIIVn0KszZ0=
8585github.com/charmbracelet/fang v0.3.1-0.20250711140230-d5ebb8c1d674 h1:+Cz+VfxD5DO+JT1LlswXWhre0HYLj6l2HW8HVGfMuC0=
@@ -90,10 +90,10 @@ github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.3.0.20250721205738-ea66aa652ee0
9090github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.3.0.20250721205738-ea66aa652ee0/go.mod h1:XIuqKpZTUXtVyeyiN1k9Tc/U7EzfaDnVc34feFHfBws=
9191github.com/charmbracelet/log/v2 v2.0.0-20250226163916-c379e29ff706 h1:WkwO6Ks3mSIGnGuSdKl9qDSyfbYK50z2wc2gGMggegE=
9292github.com/charmbracelet/log/v2 v2.0.0-20250226163916-c379e29ff706/go.mod h1:mjJGp00cxcfvD5xdCa+bso251Jt4owrQvuimJtVmEmM=
93−github.com/charmbracelet/ultraviolet v0.0.0-20250731212901-76da584cc9a5 h1:FrEzjuUbVbGd8UtZBfK8mf/IA4ExT2i3/fi+SEOv2eM=
94−github.com/charmbracelet/ultraviolet v0.0.0-20250731212901-76da584cc9a5/go.mod h1:XrrgNFfXLrFAyd9DUmrqVc3yQFVv8Uk+okj4PsNNzpc=
95−github.com/charmbracelet/x/ansi v0.9.3 h1:BXt5DHS/MKF+LjuK4huWrC6NCvHtexww7dMayh6GXd0=
96−github.com/charmbracelet/x/ansi v0.9.3/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE=
93+github.com/charmbracelet/ultraviolet v0.0.0-20250805154935-01be9d7ef65d h1:miSXsyi0ARm35O+DulTdaLYoUioWdGkoBfFoIhdqpCA=
94+github.com/charmbracelet/ultraviolet v0.0.0-20250805154935-01be9d7ef65d/go.mod h1:XrrgNFfXLrFAyd9DUmrqVc3yQFVv8Uk+okj4PsNNzpc=
95+github.com/charmbracelet/x/ansi v0.10.0 h1:jnOP9pFxY6/gw5nYjkpi6f17K0P/sN4fqT0Y1ioaORI=
96+github.com/charmbracelet/x/ansi v0.10.0/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE=
9797github.com/charmbracelet/x/cellbuf v0.0.14-0.20250516160309-24eee56f89fa h1:lphz0Z3rsiOtMYiz8axkT24i9yFiueDhJbzyNUADmME=
9898github.com/charmbracelet/x/cellbuf v0.0.14-0.20250516160309-24eee56f89fa/go.mod h1:xBlh2Yi3DL3zy/2n15kITpg0YZardf/aa/hgUaIM6Rk=
9999github.com/charmbracelet/x/exp/charmtone v0.0.0-20250708181618-a60a724ba6c3 h1:1xwHZg6eMZ9Wv5TE1UGub6ARubyOd1Lo5kPUI/6VL50=
internal/tui/components/chat/chat.go+46−19
@@ -2,7 +2,6 @@ package chat
22
33import (
44 "context"
5− "fmt"
65 "time"
76
87 "github.com/atotto/clipboard"
@@ -45,7 +44,7 @@ type MessageListCmp interface {
4544 SetSession(session.Session) tea.Cmd
4645 GoToBottom() tea.Cmd
4746 GetSelectedText() string
48− CopySelectedText() tea.Cmd
47+ CopySelectedText(bool) tea.Cmd
4948}
5049
5150// messageListCmp implements MessageListCmp, providing a virtualized list
@@ -96,6 +95,10 @@ func (m *messageListCmp) Init() tea.Cmd {
9695// Update handles incoming messages and updates the component state.
9796func (m *messageListCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
9897 switch msg := msg.(type) {
98+ case tea.KeyPressMsg:
99+ if key.Matches(msg, messages.CopyKey) && m.listCmp.HasSelection() {
100+ return m, m.CopySelectedText(true)
101+ }
99102 case tea.MouseClickMsg:
100103 x := msg.X - 1 // Adjust for padding
101104 y := msg.Y - 1 // Adjust for padding
@@ -128,11 +131,10 @@ func (m *messageListCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
128131 if msg.Button == tea.MouseLeft {
129132 if x < 0 || y < 0 || x >= m.width-2 || y >= m.height-1 {
130133 m.listCmp.SelectionStop()
131− return m, m.CopySelectedText()
134+ } else {
135+ m.listCmp.EndSelection(x, y)
136+ m.listCmp.SelectionStop()
132137 }
133− m.listCmp.EndSelection(x, y)
134− m.listCmp.SelectionStop()
135− return m, m.CopySelectedText()
136138 }
137139 return m, nil
138140 case pubsub.Event[permission.PermissionNotification]:
@@ -155,13 +157,11 @@ func (m *messageListCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
155157 u, cmd := m.listCmp.Update(msg)
156158 m.listCmp = u.(list.List[list.Item])
157159 return m, cmd
158− default:
159− var cmds []tea.Cmd
160− u, cmd := m.listCmp.Update(msg)
161− m.listCmp = u.(list.List[list.Item])
162− cmds = append(cmds, cmd)
163− return m, tea.Batch(cmds...)
164160 }
161+
162+ u, cmd := m.listCmp.Update(msg)
163+ m.listCmp = u.(list.List[list.Item])
164+ return m, cmd
165165}
166166
167167// View renders the message list or an initial screen if empty.
@@ -654,24 +654,51 @@ func (m *messageListCmp) handleMouseClick(x, y int) tea.Cmd {
654654 return nil
655655}
656656
657+// SelectionClear clears the current selection in the list component.
658+func (m *messageListCmp) SelectionClear() tea.Cmd {
659+ m.listCmp.SelectionClear()
660+ m.previousSelected = ""
661+ m.lastClickX, m.lastClickY = 0, 0
662+ m.clickCount = 0
663+ return nil
664+}
665+
666+// HasSelection checks if there is a selection in the list component.
667+func (m *messageListCmp) HasSelection() bool {
668+ return m.listCmp.HasSelection()
669+}
670+
657671// GetSelectedText returns the currently selected text from the list component.
658672func (m *messageListCmp) GetSelectedText() string {
659673 return m.listCmp.GetSelectedText(3) // 3 padding for the left border/padding
660674}
661675
662−// CopySelectedText copies the currently selected text to the clipboard.
663−func (m *messageListCmp) CopySelectedText() tea.Cmd {
664− return nil
676+// CopySelectedText copies the currently selected text to the clipboard. When
677+// clear is true, it clears the selection after copying.
678+func (m *messageListCmp) CopySelectedText(clear bool) tea.Cmd {
679+ if !m.listCmp.HasSelection() {
680+ return nil
681+ }
682+
665683 selectedText := m.GetSelectedText()
666684 if selectedText == "" {
667685 return util.ReportInfo("No text selected")
668686 }
669687
670− err := clipboard.WriteAll(selectedText)
671− if err != nil {
672− return util.ReportError(fmt.Errorf("failed to copy selected text to clipboard: %w", err))
688+ if clear {
689+ defer func() { m.SelectionClear() }()
673690 }
674− return util.ReportInfo("Selected text copied to clipboard")
691+
692+ return tea.Sequence(
693+ // We use both OSC 52 and native clipboard for compatibility with different
694+ // terminal emulators and environments.
695+ tea.SetClipboard(selectedText),
696+ func() tea.Msg {
697+ _ = clipboard.WriteAll(selectedText)
698+ return nil
699+ },
700+ util.ReportInfo("Selected text copied to clipboard"),
701+ )
675702}
676703
677704// abs returns the absolute value of an integer.
internal/tui/components/chat/messages/messages.go+11−7
@@ -25,7 +25,8 @@ import (
2525 "github.com/charmbracelet/crush/internal/tui/util"
2626)
2727
28−var copyKey = key.NewBinding(key.WithKeys("c", "y", "C", "Y"), key.WithHelp("c/y", "copy"))
28+// CopyKey is the key binding for copying message content to the clipboard.
29+var CopyKey = key.NewBinding(key.WithKeys("c", "y", "C", "Y"), key.WithHelp("c/y", "copy"))
2930
3031// MessageCmp defines the interface for message components in the chat interface.
3132// It combines standard UI model interfaces with message-specific functionality.
@@ -99,12 +100,15 @@ func (m *messageCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
99100 return m, cmd
100101 }
101102 case tea.KeyPressMsg:
102− if key.Matches(msg, copyKey) {
103− err := clipboard.WriteAll(m.message.Content().Text)
104− if err != nil {
105− return m, util.ReportError(fmt.Errorf("failed to copy message content to clipboard: %w", err))
106− }
107− return m, util.ReportInfo("Message copied to clipboard")
103+ if key.Matches(msg, CopyKey) {
104+ return m, tea.Sequence(
105+ tea.SetClipboard(m.message.Content().Text),
106+ func() tea.Msg {
107+ _ = clipboard.WriteAll(m.message.Content().Text)
108+ return nil
109+ },
110+ util.ReportInfo("Message copied to clipboard"),
111+ )
108112 }
109113 }
110114 return m, nil
internal/tui/components/chat/messages/tool.go+9−6
@@ -165,7 +165,7 @@ func (m *toolCallCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
165165 }
166166 return m, tea.Batch(cmds...)
167167 case tea.KeyPressMsg:
168− if key.Matches(msg, copyKey) {
168+ if key.Matches(msg, CopyKey) {
169169 return m, m.copyTool()
170170 }
171171 }
@@ -198,11 +198,14 @@ func (m *toolCallCmp) SetCancelled() {
198198
199199func (m *toolCallCmp) copyTool() tea.Cmd {
200200 content := m.formatToolForCopy()
201− err := clipboard.WriteAll(content)
202− if err != nil {
203− return util.ReportError(fmt.Errorf("failed to copy tool content to clipboard: %w", err))
204− }
205− return util.ReportInfo("Tool content copied to clipboard")
201+ return tea.Sequence(
202+ tea.SetClipboard(content),
203+ func() tea.Msg {
204+ _ = clipboard.WriteAll(content)
205+ return nil
206+ },
207+ util.ReportInfo("Tool content copied to clipboard"),
208+ )
206209}
207210
208211func (m *toolCallCmp) formatToolForCopy() string {
internal/tui/components/dialogs/permissions/keys.go+1−1
@@ -42,7 +42,7 @@ func DefaultKeyMap() KeyMap {
4242 key.WithHelp("s", "allow session"),
4343 ),
4444 Deny: key.NewBinding(
45− key.WithKeys("d", "D", "ctrl+d"),
45+ key.WithKeys("d", "D", "ctrl+d", "esc"),
4646 key.WithHelp("d", "deny"),
4747 ),
4848 Select: key.NewBinding(
internal/tui/components/mcp/mcp.go+1−1
@@ -68,7 +68,7 @@ func RenderMCPList(opts RenderOptions) []string {
6868 case agent.MCPStateConnected:
6969 icon = t.ItemOnlineIcon
7070 if state.ToolCount > 0 {
71− extraContent = t.S().Subtle.Render(fmt.Sprintf("(%d tools)", state.ToolCount))
71+ extraContent = t.S().Subtle.Render(fmt.Sprintf("%d tools", state.ToolCount))
7272 }
7373 case agent.MCPStateError:
7474 icon = t.ItemErrorIcon
internal/tui/exp/list/list.go+69−87
@@ -56,6 +56,7 @@ type List[T Item] interface {
5656 SelectWord(col, line int)
5757 SelectParagraph(col, line int)
5858 GetSelectedText(paddingLeft int) string
59+ HasSelection() bool
5960}
6061
6162type direction int
@@ -286,30 +287,10 @@ func (l *list[T]) handleMouseWheel(msg tea.MouseWheelMsg) (tea.Model, tea.Cmd) {
286287 return l, cmd
287288}
288289
289−// View implements List.
290−func (l *list[T]) View() string {
291− if l.height <= 0 || l.width <= 0 {
292− return ""
293− }
290+// selectionView renders the highlighted selection in the view and returns it
291+// as a string. If textOnly is true, it won't render any styles.
292+func (l *list[T]) selectionView(view string, textOnly bool) string {
294293 t := styles.CurrentTheme()
295− view := l.rendered
296− lines := strings.Split(view, "\n")
297−
298− start, end := l.viewPosition()
299− viewStart := max(0, start)
300− viewEnd := min(len(lines), end+1)
301− lines = lines[viewStart:viewEnd]
302− if l.resize {
303− return strings.Join(lines, "\n")
304− }
305− view = t.S().Base.
306− Height(l.height).
307− Width(l.width).
308− Render(strings.Join(lines, "\n"))
309−
310− if !l.hasSelection() {
311− return view
312− }
313294 area := uv.Rect(0, 0, l.width, l.height)
314295 scr := uv.NewScreenBuffer(area.Dx(), area.Dy())
315296 uv.NewStyledString(view).Draw(scr, area)
@@ -397,6 +378,8 @@ func (l *list[T]) View() string {
397378 lineTextBounds[y] = bounds
398379 }
399380
381+ var selectedText strings.Builder
382+
400383 // Second pass: apply selection highlighting
401384 for y := range scr.Height() {
402385 selBounds := lineSelections[y]
@@ -406,6 +389,11 @@ func (l *list[T]) View() string {
406389
407390 textBounds := lineTextBounds[y]
408391 if textBounds.start < 0 {
392+ if textOnly {
393+ // We don't want to get rid of all empty lines in text-only mode
394+ selectedText.WriteByte('\n')
395+ }
396+
409397 continue // No text on this line
410398 }
411399
@@ -421,16 +409,63 @@ func (l *list[T]) View() string {
421409
422410 cellStr := cell.String()
423411 if len(cellStr) > 0 && !specialChars[cellStr] {
412+ if textOnly {
413+ // Collect selected text without styles
414+ selectedText.WriteString(cell.String())
415+ continue
416+ }
417+
418+ // Text selection styling, which is a Lip Gloss style. We must
419+ // extract the values to use in a UV style, below.
420+ ts := t.TextSelection
421+
424422 cell = cell.Clone()
425− cell.Style = cell.Style.Background(t.BgOverlay).Foreground(t.White)
423+ cell.Style = cell.Style.Background(ts.GetBackground()).Foreground(ts.GetForeground())
426424 scr.SetCell(x, y, cell)
427425 }
428426 }
427+
428+ if textOnly {
429+ // Make sure we add a newline after each line of selected text
430+ selectedText.WriteByte('\n')
431+ }
432+ }
433+
434+ if textOnly {
435+ return strings.TrimSpace(selectedText.String())
429436 }
430437
431438 return scr.Render()
432439}
433440
441+// View implements List.
442+func (l *list[T]) View() string {
443+ if l.height <= 0 || l.width <= 0 {
444+ return ""
445+ }
446+ t := styles.CurrentTheme()
447+ view := l.rendered
448+ lines := strings.Split(view, "\n")
449+
450+ start, end := l.viewPosition()
451+ viewStart := max(0, start)
452+ viewEnd := min(len(lines), end+1)
453+ lines = lines[viewStart:viewEnd]
454+ if l.resize {
455+ return strings.Join(lines, "\n")
456+ }
457+ view = t.S().Base.
458+ Height(l.height).
459+ Width(l.width).
460+ Render(strings.Join(lines, "\n"))
461+
462+ if !l.hasSelection() {
463+ return view
464+ }
465+
466+ return l.selectionView(view, false)
467+}
468+
434469func (l *list[T]) viewPosition() (int, int) {
435470 start, end := 0, 0
436471 renderedLines := lipgloss.Height(l.rendered) - 1
@@ -1374,69 +1409,16 @@ func (l *list[T]) SelectParagraph(col, line int) {
13741409 l.selectionActive = false // Not actively selecting, just selected
13751410}
13761411
1412+// HasSelection returns whether there is an active selection.
1413+func (l *list[T]) HasSelection() bool {
1414+ return l.hasSelection()
1415+}
1416+
13771417// GetSelectedText returns the currently selected text.
13781418func (l *list[T]) GetSelectedText(paddingLeft int) string {
1379− return ""
1380− // if !l.hasSelection() {
1381− // return ""
1382− // }
1383− //
1384− // startLine := l.selectionStartLine
1385− // endLine := l.selectionEndLine
1386− // startCol := l.selectionStartCol
1387− // endCol := l.selectionEndCol
1388− //
1389− // if l.direction == DirectionBackward {
1390− // startLine = (lipgloss.Height(l.rendered) - 1) - startLine
1391− // endLine = (lipgloss.Height(l.rendered) - 1) - endLine
1392− // }
1393− //
1394− // if l.offset > 0 {
1395− // if l.direction == DirectionBackward {
1396− // startLine += l.offset
1397− // endLine += l.offset
1398− // } else {
1399− // startLine -= l.offset
1400− // endLine -= l.offset
1401− // }
1402− // }
1403− //
1404− // lines := strings.Split(l.rendered, "\n")
1405− //
1406− // if startLine < 0 || endLine < 0 || startLine >= len(lines) || endLine >= len(lines) {
1407− // return ""
1408− // }
1409− //
1410− // var result strings.Builder
1411− // for i := range lines {
1412− // lines[i] = ansi.Strip(lines[i])
1413− // for _, icon := range styles.SelectionIgnoreIcons {
1414− // lines[i] = strings.ReplaceAll(lines[i], icon, " ")
1415− // }
1416− //
1417− // if i == startLine {
1418− // if startCol < 0 || startCol >= len(lines[i]) {
1419− // startCol = 0
1420− // }
1421− // if startCol < paddingLeft {
1422− // startCol = paddingLeft
1423− // }
1424− // if i != endLine {
1425− // endCol = len(lines[i])
1426− // }
1427− // result.WriteString(strings.TrimRightFunc(lines[i][startCol:endCol], unicode.IsSpace))
1428− // } else if i > startLine && i < endLine {
1429− // result.WriteString(strings.TrimRightFunc(lines[i][paddingLeft:], unicode.IsSpace))
1430− // } else if i == endLine {
1431− // if endCol < 0 || endCol >= len(lines[i]) {
1432− // endCol = len(lines[i])
1433− // }
1434− // if endCol < paddingLeft {
1435− // endCol = paddingLeft
1436− // }
1437− // result.WriteString(strings.TrimRightFunc(lines[i][paddingLeft:endCol], unicode.IsSpace))
1438− // }
1439− // }
1440− //
1441− // return result.String()
1419+ if !l.hasSelection() {
1420+ return ""
1421+ }
1422+
1423+ return l.selectionView(l.View(), true)
14421424}
internal/tui/page/chat/chat.go+11−5
@@ -19,6 +19,7 @@ import (
1919 "github.com/charmbracelet/crush/internal/tui/components/chat"
2020 "github.com/charmbracelet/crush/internal/tui/components/chat/editor"
2121 "github.com/charmbracelet/crush/internal/tui/components/chat/header"
22+ "github.com/charmbracelet/crush/internal/tui/components/chat/messages"
2223 "github.com/charmbracelet/crush/internal/tui/components/chat/sidebar"
2324 "github.com/charmbracelet/crush/internal/tui/components/chat/splash"
2425 "github.com/charmbracelet/crush/internal/tui/components/completions"
@@ -172,10 +173,18 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
172173 }
173174 return p, nil
174175 case tea.MouseClickMsg:
176+ if p.isMouseOverChat(msg.X, msg.Y) {
177+ p.focusedPane = PanelTypeChat
178+ p.chat.Focus()
179+ p.editor.Blur()
180+ } else {
181+ p.focusedPane = PanelTypeEditor
182+ p.editor.Focus()
183+ p.chat.Blur()
184+ }
175185 u, cmd := p.chat.Update(msg)
176186 p.chat = u.(chat.MessageListCmp)
177187 return p, cmd
178− return p, nil
179188 case tea.MouseMotionMsg:
180189 if msg.Button == tea.MouseLeft {
181190 u, cmd := p.chat.Update(msg)
@@ -857,10 +866,7 @@ func (p *chatPage) Help() help.KeyMap {
857866 key.WithKeys("up", "down"),
858867 key.WithHelp("↑↓", "scroll"),
859868 ),
860− key.NewBinding(
861− key.WithKeys("c", "y"),
862− key.WithHelp("c/y", "copy"),
863− ),
869+ messages.CopyKey,
864870 )
865871 fullList = append(fullList,
866872 []key.Binding{
internal/tui/styles/crush.go → internal/tui/styles/charmtone.gorenamed+5−2
@@ -5,9 +5,9 @@ import (
55 "github.com/charmbracelet/x/exp/charmtone"
66)
77
8−func NewCrushTheme() *Theme {
8+func NewCharmtoneTheme() *Theme {
99 t := &Theme{
10− Name: "crush",
10+ Name: "charmtone",
1111 IsDark: true,
1212
1313 Primary: charmtone.Charple,
@@ -56,6 +56,9 @@ func NewCrushTheme() *Theme {
5656 Cherry: charmtone.Cherry,
5757 }
5858
59+ // Text selection.
60+ t.TextSelection = lipgloss.NewStyle().Foreground(charmtone.Salt).Background(charmtone.Charple)
61+
5962 // LSP and MCP status.
6063 t.ItemOfflineIcon = lipgloss.NewStyle().Foreground(charmtone.Squid).SetString("●")
6164 t.ItemBusyIcon = t.ItemOfflineIcon.Foreground(charmtone.Citron)
internal/tui/styles/theme.go+9−6
@@ -74,6 +74,9 @@ type Theme struct {
7474 RedLight color.Color
7575 Cherry color.Color
7676
77+ // Text selection.
78+ TextSelection lipgloss.Style
79+
7780 // LSP and MCP status indicators.
7881 ItemOfflineIcon lipgloss.Style
7982 ItemBusyIcon lipgloss.Style
@@ -491,26 +494,26 @@ func SetDefaultManager(m *Manager) {
491494
492495func DefaultManager() *Manager {
493496 if defaultManager == nil {
494− defaultManager = NewManager("crush")
497+ defaultManager = NewManager()
495498 }
496499 return defaultManager
497500}
498501
499502func CurrentTheme() *Theme {
500503 if defaultManager == nil {
501− defaultManager = NewManager("crush")
504+ defaultManager = NewManager()
502505 }
503506 return defaultManager.Current()
504507}
505508
506−func NewManager(defaultTheme string) *Manager {
509+func NewManager() *Manager {
507510 m := &Manager{
508511 themes: make(map[string]*Theme),
509512 }
510513
511− m.Register(NewCrushTheme())
512−
513− m.current = m.themes[defaultTheme]
514+ t := NewCharmtoneTheme() // default theme
515+ m.Register(t)
516+ m.current = m.themes[t.Name]
514517
515518 return m
516519}