Allow using keys on delete confirmation popup

This commit is contained in:
Kovid Goyal 2021-05-23 10:54:03 +05:30
parent ef11d26921
commit b097ecce99
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -81,6 +81,7 @@ class DeleteBook: # {{{
set_css(container, background_color=get_color('window-background')) set_css(container, background_color=get_color('window-background'))
container.appendChild(E.div( container.appendChild(E.div(
style='display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%', style='display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%',
tabindex='0',
E.div(style='margin:1ex 1em; max-width: 80%', E.div(style='margin:1ex 1em; max-width: 80%',
E.h2(self.question), E.h2(self.question),
E.div(style='display:flex; justify-content:flex-end; margin-top:1rem', E.div(style='display:flex; justify-content:flex-end; margin-top:1rem',
@ -88,8 +89,19 @@ class DeleteBook: # {{{
E.span('\xa0'), E.span('\xa0'),
create_button(_('Cancel'), action=self.cancel), create_button(_('Cancel'), action=self.cancel),
) )
) ),
onkeyup=def(ev):
if ev.key is 'Escape':
ev.stopPropagation(), ev.preventDefault()
self.cancel()
elif ev.key is 'Enter' or ev.key is 'Return':
ev.stopPropagation(), ev.preventDefault()
self.delete_book()
)) ))
window.setTimeout(self.focus_me, 0)
def focus_me(self):
document.getElementById(self.container_id).lastChild.focus()
def show_working(self): def show_working(self):
container = document.getElementById(self.container_id) container = document.getElementById(self.container_id)