Allow pressing the down arrow key to show the completion popup

Also have the enter key close the completion popup, applying any
selected completion first.
This commit is contained in:
Kovid Goyal 2019-11-14 15:47:04 +05:30
parent 55ca95bb34
commit 028241eb0e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 12 additions and 1 deletions

View File

@ -37,6 +37,11 @@ class EditWithComplete:
event.preventDefault(), event.stopPropagation()
return
if event.key is 'Enter':
if self.completion_popup.is_visible:
if self.apply_completion(self.completion_popup.current_text):
self.completion_popup.hide()
event.preventDefault(), event.stopPropagation()
return
if self.onenterkey:
event.preventDefault(), event.stopPropagation()
self.onenterkey()
@ -47,6 +52,12 @@ class EditWithComplete:
else:
self.completion_popup.move_highlight()
event.preventDefault(), event.stopPropagation()
elif event.key is 'ArrowDown':
ti = self.text_input
if not ti.value:
self.completion_popup.set_query('')
self.completion_popup.popup(ti)
event.preventDefault(), event.stopPropagation()
def oninput(self, event):
ti = self.text_input

View File

@ -93,7 +93,7 @@ class CompletionPopup:
def set_all_items(self, items):
self.items = list(items)
self.matches = []
self.applied_query = ''
self.applied_query = None
def add_associated_widget(self, widget_or_id):
if jstype(widget_or_id) is not 'string':