Skip to content

Commit 233a3fa

Browse files
committed
Remove unnecessary codes from delegate.go
1 parent d1c756e commit 233a3fa

File tree

1 file changed

+10
-34
lines changed

1 file changed

+10
-34
lines changed

internal/ui/delegate.go

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package ui
33
import (
44
"fmt"
55
"io"
6-
"strings"
76

87
"github.com/charmbracelet/bubbles/list"
98
tea "github.com/charmbracelet/bubbletea"
@@ -64,37 +63,25 @@ func (d testCaseItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
6463
}
6564

6665
func (d testCaseItemDelegate) Render(w io.Writer, m list.Model, index int, item list.Item) {
67-
var (
68-
title, desc string
69-
matchedRunes []int
70-
)
71-
7266
i := item.(*testCaseItem)
73-
title = i.name
74-
desc = i.path
67+
title := i.name
68+
desc := i.path
7569

7670
if m.Width() <= 0 {
7771
return
7872
}
7973

8074
textwidth := m.Width() - listNormalTitleStyle.GetPaddingLeft() - listNormalTitleStyle.GetPaddingRight()
8175
title = ansi.Truncate(title, textwidth, ellipsis)
82-
83-
var lines []string
84-
for i, line := range strings.Split(desc, "\n") {
85-
if i >= d.Height()-1 {
86-
break
87-
}
88-
lines = append(lines, ansi.Truncate(line, textwidth, ellipsis))
89-
}
90-
desc = strings.Join(lines, "\n")
76+
desc = ansi.Truncate(desc, textwidth, ellipsis)
9177

9278
var (
9379
isSelected = index == m.Index()
9480
emptyFilter = m.FilterState() == list.Filtering && m.FilterValue() == ""
9581
isFiltered = m.FilterState() == list.Filtering || m.FilterState() == list.FilterApplied
9682
)
9783

84+
var matchedRunes []int
9885
if isFiltered && index < len(m.VisibleItems()) {
9986
matchedRunes = m.MatchesForItem(index)
10087
}
@@ -150,38 +137,27 @@ func (d historyItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
150137
}
151138

152139
func (d historyItemDelegate) Render(w io.Writer, m list.Model, index int, item list.Item) {
153-
var (
154-
title, desc, runAt string
155-
matchedRunes []int
156-
)
157-
158140
i := item.(*historyItem)
159-
title = i.nameForView
160-
desc = i.path
161-
runAt = i.runAt
141+
title := i.nameForView
142+
desc := i.path
143+
runAt := i.runAt
162144

163145
if m.Width() <= 0 {
164146
return
165147
}
166148

167149
textwidth := m.Width() - listNormalTitleStyle.GetPaddingLeft() - listNormalTitleStyle.GetPaddingRight()
168150
title = ansi.Truncate(title, textwidth, ellipsis)
169-
170-
var lines []string
171-
for i, line := range strings.Split(desc, "\n") {
172-
if i >= d.Height()-1 {
173-
break
174-
}
175-
lines = append(lines, ansi.Truncate(line, textwidth, ellipsis))
176-
}
177-
desc = strings.Join(lines, "\n")
151+
desc = ansi.Truncate(desc, textwidth, ellipsis)
152+
runAt = ansi.Truncate(runAt, textwidth, ellipsis)
178153

179154
var (
180155
isSelected = index == m.Index()
181156
emptyFilter = m.FilterState() == list.Filtering && m.FilterValue() == ""
182157
isFiltered = m.FilterState() == list.Filtering || m.FilterState() == list.FilterApplied
183158
)
184159

160+
var matchedRunes []int
185161
if isFiltered && index < len(m.VisibleItems()) {
186162
matchedRunes = m.MatchesForItem(index)
187163
}

0 commit comments

Comments
 (0)