tui: rename
This commit is contained in:
parent
2fed682969
commit
ce7b07ad95
@ -73,7 +73,7 @@ func NewWithGroups(groups []OptionGroup) Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m.filterItems()
|
m.filterItems()
|
||||||
m.content.SetContent(m.renderList())
|
m.content.SetContent(m.renderOptionsList())
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,15 +113,13 @@ func (m *Model) filterItems() {
|
|||||||
if len(m.filteredIndices) > 0 && prevSelection != nil {
|
if len(m.filteredIndices) > 0 && prevSelection != nil {
|
||||||
// Preserve previous selection if possible
|
// Preserve previous selection if possible
|
||||||
for i, filterIdx := range m.filteredIndices {
|
for i, filterIdx := range m.filteredIndices {
|
||||||
if prevSelection.groupIndex == filterIdx.groupIndex {
|
if prevSelection.groupIndex == filterIdx.groupIndex && prevSelection.optionIndex == filterIdx.optionIndex {
|
||||||
if prevSelection.optionIndex == filterIdx.optionIndex {
|
|
||||||
m.selected = i
|
m.selected = i
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if !found {
|
if !found {
|
||||||
m.selected = 0
|
m.selected = 0
|
||||||
}
|
}
|
||||||
@ -180,7 +178,7 @@ func (m *Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) refreshContent() {
|
func (m *Model) refreshContent() {
|
||||||
m.content.SetContent(m.renderList())
|
m.content.SetContent(m.renderOptionsList())
|
||||||
m.ensureSelectedVisible()
|
m.ensureSelectedVisible()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,12 +217,12 @@ func (m *Model) View() string {
|
|||||||
return lipgloss.JoinVertical(lipgloss.Left, parts...)
|
return lipgloss.JoinVertical(lipgloss.Left, parts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) renderList() string {
|
func (m *Model) renderOptionsList() string {
|
||||||
var sb strings.Builder
|
|
||||||
yOffset := 0
|
yOffset := 0
|
||||||
lastGroupIndex := -1
|
lastGroupIndex := -1
|
||||||
m.itemYOffsets = make([]int, len(m.filteredIndices))
|
m.itemYOffsets = make([]int, len(m.filteredIndices))
|
||||||
|
|
||||||
|
var sb strings.Builder
|
||||||
for i, idx := range m.filteredIndices {
|
for i, idx := range m.filteredIndices {
|
||||||
if idx.groupIndex != lastGroupIndex {
|
if idx.groupIndex != lastGroupIndex {
|
||||||
group := m.optionGroups[idx.groupIndex].Name
|
group := m.optionGroups[idx.groupIndex].Name
|
||||||
@ -258,6 +256,5 @@ func (m *Model) renderList() string {
|
|||||||
sb.WriteRune('\n')
|
sb.WriteRune('\n')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.String()
|
return sb.String()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user