From 6cfeec7245177ad74071d00841fbe05952d38e5a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 16 Mar 2022 13:20:46 +0530 Subject: [PATCH] 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) --- src/pyj/read_book/prefs/main.pyj | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/pyj/read_book/prefs/main.pyj b/src/pyj/read_book/prefs/main.pyj index be3bbe5517..dd2947eab3 100644 --- a/src/pyj/read_book/prefs/main.pyj +++ b/src/pyj/read_book/prefs/main.pyj @@ -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)