do not highlight line if there are no items to display

This commit is contained in:
Jesse Duffield
2022-04-15 14:01:13 +10:00
parent 00afa30ebf
commit b838b74801
6 changed files with 16 additions and 24 deletions

View File

@@ -37,6 +37,8 @@ func formatListFooter(selectedLineIdx int, length int) string {
func (self *ListContextTrait) HandleFocus(opts ...types.OnFocusOpts) error {
self.FocusLine()
self.viewTrait.SetHighlight(self.list.Len() > 0)
return self.Context.HandleFocus(opts...)
}

View File

@@ -25,7 +25,12 @@ func (self *ListCursor) GetSelectedLineIdx() int {
}
func (self *ListCursor) SetSelectedLineIdx(value int) {
self.selectedIdx = utils.Clamp(value, 0, self.list.Len()-1)
clampedValue := -1
if self.list.Len() > 0 {
clampedValue = utils.Clamp(value, 0, self.list.Len()-1)
}
self.selectedIdx = clampedValue
}
// moves the cursor up or down by the given amount

View File

@@ -31,6 +31,10 @@ func (self *ViewTrait) SetContent(content string) {
self.view.SetContent(content)
}
func (self *ViewTrait) SetHighlight(highlight bool) {
self.view.Highlight = highlight
}
func (self *ViewTrait) SetFooter(value string) {
self.view.Footer = value
}