From 768070ef7b6ca9718833b7b1cc19fa029c0a9eeb Mon Sep 17 00:00:00 2001 From: Oliver <480930+rivo@users.noreply.github.com> Date: Thu, 19 Jul 2018 12:46:48 +0200 Subject: [PATCH] Hitting Escape on a drop-down selection resets it. --- dropdown.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dropdown.go b/dropdown.go index 1430748..ab55e3d 100644 --- a/dropdown.go +++ b/dropdown.go @@ -354,6 +354,7 @@ func (d *DropDown) InputHandler() func(event *tcell.EventKey, setFocus func(p Pr // Hand control over to the list. d.open = true + optionBefore := d.currentOption d.list.SetSelectedFunc(func(index int, mainText, secondaryText string, shortcut rune) { // An option was selected. Close the list again. d.open = false @@ -374,6 +375,10 @@ func (d *DropDown) InputHandler() func(event *tcell.EventKey, setFocus func(p Pr d.prefix = string(r[:len(r)-1]) } evalPrefix() + } else if event.Key() == tcell.KeyEscape { + d.open = false + d.currentOption = optionBefore + setFocus(d) } else { d.prefix = "" }