1
0
mirror of https://github.com/rivo/tview.git synced 2025-04-24 13:48:56 +08:00

Fix panic when navigating empty list

Resolves #407.
This commit is contained in:
Trevor Slocum 2020-02-17 08:27:42 -08:00
parent ae3d8cac5e
commit babee1042c

13
list.go
View File

@ -474,6 +474,15 @@ func (l *List) Draw(screen tcell.Screen) {
// InputHandler returns the handler for this primitive.
func (l *List) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) {
return l.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) {
if event.Key() == tcell.KeyEscape {
if l.done != nil {
l.done()
}
return
} else if len(l.items) == 0 {
return
}
previousItem := l.currentItem
switch key := event.Key(); key {
@ -499,10 +508,6 @@ func (l *List) InputHandler() func(event *tcell.EventKey, setFocus func(p Primit
l.selected(l.currentItem, item.MainText, item.SecondaryText, item.Shortcut)
}
}
case tcell.KeyEscape:
if l.done != nil {
l.done()
}
case tcell.KeyRune:
ch := event.Rune()
if ch != ' ' {