Fix panic when navigating empty list

This commit is contained in:
Trevor Slocum 2020-02-17 08:25:21 -08:00
parent c6599f4ee2
commit 7175730374
2 changed files with 10 additions and 4 deletions

View File

@ -1,4 +1,5 @@
v1.4.4 (WIP)
- Fix panic when navigating empty list
- Fix resize event dimensions on Windows
- Clarify that Box does not have inner text

13
list.go
View File

@ -514,6 +514,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 {
@ -539,10 +548,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 != ' ' {