e7a94cb7cb4198756157f06bdc999f7e094eacd8

Author
石岳峰 <132282304+syf2211@users.noreply.github.com>
Committer
GitHub <noreply@github.com>
Date

Message

fix(ui): prevent repo duplication when copying from filtered list (#902)

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Kieran Klukas <kieran@dunkirk.sh>

Diff

 1diff --git a/pkg/ui/pages/selection/item.go b/pkg/ui/pages/selection/item.go
 2index b6b3a02fac890cfaf5507e4aa87398a4596824b0..e5c23187cd33178a2f6f8752d05dc4dd81376ada 100644
 3--- a/pkg/ui/pages/selection/item.go
 4+++ b/pkg/ui/pages/selection/item.go
 5@@ -100,7 +100,7 @@ func (i Item) Command() string {
 6 type ItemDelegate struct {
 7 	common     *common.Common
 8 	activePane *pane
 9-	copiedIdx  int
10+	copiedID   string
11 }
12 
13 // NewItemDelegate creates a new ItemDelegate.
14@@ -108,7 +108,6 @@ func NewItemDelegate(common *common.Common, activePane *pane) *ItemDelegate {
15 	return &ItemDelegate{
16 		common:     common,
17 		activePane: activePane,
18-		copiedIdx:  -1,
19 	}
20 }
21 
22@@ -129,7 +128,6 @@ func (d *ItemDelegate) Spacing() int { return 1 }
23 
24 // Update implements list.ItemDelegate.
25 func (d *ItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
26-	idx := m.Index()
27 	item, ok := m.SelectedItem().(Item)
28 	if !ok {
29 		return nil
30@@ -138,10 +136,10 @@ func (d *ItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
31 	case tea.KeyPressMsg:
32 		switch {
33 		case key.Matches(msg, d.common.KeyMap.Copy):
34-			d.copiedIdx = idx
35+			d.copiedID = item.ID()
36 			return tea.Batch(
37 				tea.SetClipboard(item.Command()),
38-				m.SetItem(idx, item),
39+				m.SetItem(m.GlobalIndex(), item),
40 			)
41 		}
42 	}
43@@ -207,10 +205,10 @@ func (d *ItemDelegate) Render(w io.Writer, m list.Model, index int, listItem lis
44 
45 	cmd := i.Command()
46 	cmdStyler := styles.Command.Render
47-	if d.copiedIdx == index {
48+	if d.copiedID == i.ID() {
49 		cmd = "(copied to clipboard)"
50 		cmdStyler = styles.Desc.Render
51-		d.copiedIdx = -1
52+		d.copiedID = ""
53 	}
54 	cmd = common.TruncateString(cmd, m.Width()-styles.Base.GetHorizontalFrameSize())
55 	s.WriteString(cmdStyler(cmd))