The open source coding agent.
TypeScript
add toast for copy
Dax Raad90d37c98f8f8
diff --git a/packages/tui/internal/components/chat/messages.go b/packages/tui/internal/components/chat/messages.goindex 718f41924ea..b857c459452 100644--- a/packages/tui/internal/components/chat/messages.go+++ b/packages/tui/internal/components/chat/messages.go@@ -46,7 +46,7 @@ type messagesComponent struct {tail boolpartCount intlineCount int- selection selection+ selection *selection}type selection struct {@@ -56,18 +56,14 @@ type selection struct {endY int}-func (s selection) selecting() bool {- return s.startX >= 0 && s.startY >= 0-}-func (s selection) hasCompleteSelection() bool {return s.startX >= 0 && s.startY >= 0 && s.endX >= 0 && s.endY >= 0}-func (s selection) coords(offset int) selection {+func (s selection) coords(offset int) *selection {// selecting backwardsif s.startY > s.endY && s.endY >= 0 {- return selection{+ return &selection{startX: max(0, s.endX-1),startY: s.endY - offset,endX: s.startX + 1,@@ -77,7 +73,7 @@ func (s selection) coords(offset int) selection {// selecting backwards same lineif s.startY == s.endY && s.startX >= s.endX {- return selection{+ return &selection{startY: s.startY - offset,startX: max(0, s.endX-1),endY: s.endY - offset,@@ -85,7 +81,7 @@ func (s selection) coords(offset int) selection {}}- return selection{+ return &selection{startX: s.startX,startY: s.startY - offset,endX: s.endX,@@ -108,7 +104,7 @@ func (m *messagesComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {slog.Info("mouse", "x", msg.X, "y", msg.Y, "offset", m.viewport.YOffset)y := msg.Y + m.viewport.YOffsetif y > 0 {- m.selection = selection{+ m.selection = &selection{startY: y,startX: msg.X,endY: -1,@@ -120,8 +116,8 @@ func (m *messagesComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {}case tea.MouseMotionMsg:- if m.selection.selecting() {- m.selection = selection{+ if m.selection != nil {+ m.selection = &selection{startX: m.selection.startX,startY: m.selection.startY,endX: msg.X + 1,@@ -131,16 +127,12 @@ func (m *messagesComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {}case tea.MouseReleaseMsg:- if m.selection.hasCompleteSelection() {- m.selection = selection{- startX: -1,- startY: -1,- endX: -1,- endY: -1,- }- return m, tea.Batch(- app.SetClipboard(strings.Join(m.clipboard, "\n")),+ if m.selection != nil && m.selection.hasCompleteSelection() {+ m.selection = nil+ return m, tea.Sequence(m.renderView(),+ app.SetClipboard(strings.Join(m.clipboard, "\n")),+ toast.NewSuccessToast("Copied to clipboard"),)}case tea.WindowSizeMsg:@@ -491,12 +483,14 @@ func (m *messagesComponent) renderView() tea.Cmd {final := []string{}clipboard := []string{}- selection := m.selection.coords(lipgloss.Height(header) + 1)- hasSelection := m.selection.selecting()+ var selection *selection+ if m.selection != nil {+ selection = m.selection.coords(lipgloss.Height(header) + 1)+ }for _, block := range blocks {lines := strings.Split(block, "\n")for index, line := range lines {- if !hasSelection || index == 0 || index == len(lines)-1 {+ if selection == nil || index == 0 || index == len(lines)-1 {final = append(final, line)continue}@@ -776,11 +770,5 @@ func NewMessagesComponent(app *app.App) MessagesComponent {showToolDetails: true,cache: NewPartCache(),tail: true,- selection: selection{- startX: -1,- startY: -1,- endX: -1,- endY: -1,- },}}