From ce7b07ad95641ee477765c873ffc866204fbfc5d Mon Sep 17 00:00:00 2001 From: Matt Low Date: Mon, 30 Sep 2024 04:32:47 +0000 Subject: [PATCH] tui: rename --- pkg/tui/bubbles/list/list.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/pkg/tui/bubbles/list/list.go b/pkg/tui/bubbles/list/list.go index 946e313..c894da9 100644 --- a/pkg/tui/bubbles/list/list.go +++ b/pkg/tui/bubbles/list/list.go @@ -73,7 +73,7 @@ func NewWithGroups(groups []OptionGroup) Model { } m.filterItems() - m.content.SetContent(m.renderList()) + m.content.SetContent(m.renderOptionsList()) return m } @@ -113,12 +113,10 @@ func (m *Model) filterItems() { if len(m.filteredIndices) > 0 && prevSelection != nil { // Preserve previous selection if possible for i, filterIdx := range m.filteredIndices { - if prevSelection.groupIndex == filterIdx.groupIndex { - if prevSelection.optionIndex == filterIdx.optionIndex { - m.selected = i - found = true - break - } + if prevSelection.groupIndex == filterIdx.groupIndex && prevSelection.optionIndex == filterIdx.optionIndex { + m.selected = i + found = true + break } } } @@ -165,7 +163,7 @@ func (m *Model) Update(msg tea.Msg) (Model, tea.Cmd) { return *m, func() tea.Msg { idx := m.filteredIndices[m.selected] return MsgOptionSelected{ - ID: m.ID, + ID: m.ID, Option: m.optionGroups[idx.groupIndex].Options[idx.optionIndex], } } @@ -180,7 +178,7 @@ func (m *Model) Update(msg tea.Msg) (Model, tea.Cmd) { } func (m *Model) refreshContent() { - m.content.SetContent(m.renderList()) + m.content.SetContent(m.renderOptionsList()) m.ensureSelectedVisible() } @@ -219,12 +217,12 @@ func (m *Model) View() string { return lipgloss.JoinVertical(lipgloss.Left, parts...) } -func (m *Model) renderList() string { - var sb strings.Builder +func (m *Model) renderOptionsList() string { yOffset := 0 lastGroupIndex := -1 m.itemYOffsets = make([]int, len(m.filteredIndices)) + var sb strings.Builder for i, idx := range m.filteredIndices { if idx.groupIndex != lastGroupIndex { group := m.optionGroups[idx.groupIndex].Name @@ -258,6 +256,5 @@ func (m *Model) renderList() string { sb.WriteRune('\n') } } - return sb.String() }