Răsfoiți Sursa

do not copy empty strings

Dax Raad 7 luni în urmă
părinte
comite
6867658c0f
1 a modificat fișierele cu 4 adăugiri și 6 ștergeri
  1. 4 6
      packages/tui/internal/components/chat/messages.go

+ 4 - 6
packages/tui/internal/components/chat/messages.go

@@ -56,10 +56,6 @@ type selection struct {
 	endY   int
 }
 
-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 {
 	// selecting backwards
 	if s.startY > s.endY && s.endY >= 0 {
@@ -127,11 +123,13 @@ func (m *messagesComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 		}
 
 	case tea.MouseReleaseMsg:
-		if m.selection != nil && m.selection.hasCompleteSelection() {
+		if m.selection != nil && len(m.clipboard) > 0 {
+			content := strings.Join(m.clipboard, "\n")
 			m.selection = nil
+			m.clipboard = []string{}
 			return m, tea.Sequence(
 				m.renderView(),
-				app.SetClipboard(strings.Join(m.clipboard, "\n")),
+				app.SetClipboard(content),
 				toast.NewSuccessToast("Copied to clipboard"),
 			)
 		}