Fix panic with empty list

This commit is contained in:
Rob Warner 2018-05-09 18:13:40 -04:00
parent 213c37c368
commit 2899c719ca
1 changed files with 8 additions and 6 deletions

14
list.go
View File

@ -296,12 +296,14 @@ func (l *List) InputHandler() func(event *tcell.EventKey, setFocus func(p Primit
case tcell.KeyPgUp:
l.currentItem -= 5
case tcell.KeyEnter:
item := l.items[l.currentItem]
if item.Selected != nil {
item.Selected()
}
if l.selected != nil {
l.selected(l.currentItem, item.MainText, item.SecondaryText, item.Shortcut)
if l.currentItem >= 0 && l.currentItem < len(l.items) {
item := l.items[l.currentItem]
if item.Selected != nil {
item.Selected()
}
if l.selected != nil {
l.selected(l.currentItem, item.MainText, item.SecondaryText, item.Shortcut)
}
}
case tcell.KeyEscape:
if l.done != nil {