From babee1042caf0149b4cc9e9ad18b0b92036afd6b Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Mon, 17 Feb 2020 08:27:42 -0800 Subject: [PATCH] Fix panic when navigating empty list Resolves #407. --- list.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/list.go b/list.go index 14ecf43..bc55f5a 100644 --- a/list.go +++ b/list.go @@ -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 != ' ' {