More elegant handling for pressing enter with no valid current input in the hints kitten

This commit is contained in:
Kovid Goyal 2018-05-18 21:28:43 +05:30
parent 18893f86ce
commit 26df57a1c7
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -128,9 +128,15 @@ def on_key(self, key_event):
self.current_text = None
self.draw_screen()
elif key_event is enter_key and self.current_input:
idx = decode_hint(self.current_input)
self.chosen = self.index_map[idx].text
self.quit_loop(0)
try:
idx = decode_hint(self.current_input)
self.chosen = self.index_map[idx].text
except Exception:
self.current_input = ''
self.current_text = None
self.draw_screen()
else:
self.quit_loop(0)
elif key_event.key is ESCAPE:
self.quit_loop(1)