diff --git a/CHANGELOG b/CHANGELOG index fb4d58d..ccea01a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 diff --git a/list.go b/list.go index d36c3c9..b77e24b 100644 --- a/list.go +++ b/list.go @@ -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 != ' ' {