Viewer: Fix ESC key not working reliably in preference panels

Fixes #1964505 [[Enhancement - Content server] Pressing ESC to close Preferences page and subpages](https://bugs.launchpad.net/calibre/+bug/1964505)
This commit is contained in:
Kovid Goyal 2022-03-16 13:20:46 +05:30
parent 852b9d8cd2
commit 6cfeec7245
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -30,6 +30,13 @@ class Prefs:
self.main_title = _('Configure book reader')
container.appendChild(E.div(
style='contain: paint; width: 100%; height: 100%; display: flex; flex-direction: column',
tabindex='-1',
onkeydown=def(ev):
if ev.key is 'Escape':
ev.stopPropagation(), ev.preventDefault()
if not self.cancel():
self.close_func()
,
E.div(), E.div(style='flex-grow: 100; overflow: auto')
))
container = container.firstChild
@ -48,6 +55,7 @@ class Prefs:
if self.stack.length > 1:
self.stack.pop()
self.display_panel(self.stack[-1])
return True
def onclose(self):
if self.stack.length > 1:
@ -74,6 +82,8 @@ class Prefs:
container = self.container
clear(container)
getattr(self, 'display_' + which)(container)
container.setAttribute('tabindex', '-1')
container.focus()
def show_panel(self, which):
self.stack.push(which)