tui: rename

This commit is contained in:
Matt Low 2024-09-30 04:32:47 +00:00
parent 2fed682969
commit ce7b07ad95

View File

@ -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()
}