From 66f427eef474125ad104cf7a143fe73e4e7b2503 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 2 Mar 2022 19:08:16 +0530 Subject: [PATCH] Fix #1961465 [[Enhancement - Content server] ESC to close the Search for books page](https://bugs.launchpad.net/calibre/+bug/1961465) --- src/pyj/book_list/prefs.pyj | 9 +++++++++ src/pyj/book_list/search.pyj | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/pyj/book_list/prefs.pyj b/src/pyj/book_list/prefs.pyj index f38b172afe..1311c0ddfa 100644 --- a/src/pyj/book_list/prefs.pyj +++ b/src/pyj/book_list/prefs.pyj @@ -227,6 +227,12 @@ def reset_to_defaults(): def prefs_panel_handler(title_func, get_prefs_data, on_close=None, icon='close'): + def onkeydown(container_id, close_action, ev): + if ev.key is 'Escape': + ev.preventDefault(), ev.stopPropagation() + close_action() + + def close_action(): if on_close is not None: on_close() @@ -234,8 +240,11 @@ def prefs_panel_handler(title_func, get_prefs_data, on_close=None, icon='close') def init_prefs_panel(container_id): container = document.getElementById(container_id) + container.addEventListener('keydown', onkeydown.bind(None, container_id, close_action), {'passive': False, 'capture': True}) + container.setAttribute('tabindex', '0') create_top_bar(container, title=title_func(), action=close_action, icon=icon) container.appendChild(E.div()) create_prefs_widget(container.lastChild, get_prefs_data()) + container.focus() return init_prefs_panel diff --git a/src/pyj/book_list/search.pyj b/src/pyj/book_list/search.pyj index 75e691b3c6..3b15a2e9f7 100644 --- a/src/pyj/book_list/search.pyj +++ b/src/pyj/book_list/search.pyj @@ -513,12 +513,21 @@ def tb_config_panel_handler(): # }}} +def onkeydown(container_id, close_action, ev): + if ev.key is 'Escape': + ev.preventDefault(), ev.stopPropagation() + close_action() + + def init(container_id): if not library_data.sortable_fields: show_panel('book_list', replace=True) return container = document.getElementById(container_id) + container.setAttribute('tabindex', '0') + container.addEventListener('keydown', onkeydown.bind(None, container_id, back), {'passive': False, 'capture': True}) create_top_bar(container, title=_('Search for books'), action=back, icon='close') add_button(container, icon='cogs', action=show_panel.bind(None, 'book_list^search^prefs'), tooltip=_('Configure Tag browser')) container.appendChild(E.div(class_=CLASS_NAME)) create_search_panel(container.lastChild) + container.focus()