Merge pull request #112 from hoop33/master

Fix panic with <Enter> on empty list
This commit is contained in:
rivo 2018-05-12 15:28:18 +02:00 committed by GitHub
commit 0a4caa5b6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 6 deletions

View File

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