diff --git a/src/pyj/book_list/book_details.pyj b/src/pyj/book_list/book_details.pyj index 6e65363b40..5a0b309a82 100644 --- a/src/pyj/book_list/book_details.pyj +++ b/src/pyj/book_list/book_details.pyj @@ -605,7 +605,7 @@ def check_for_books_loaded(): create_book_details(container) -def onkeydown(container_id, ev): +def onkeydown(container_id, close_action, ev): if render_book.book_id: if not ev.altKey and not ev.ctrlKey and not ev.metaKey and not ev.shiftKey: if ev.key is 'ArrowLeft': @@ -614,6 +614,9 @@ def onkeydown(container_id, ev): elif ev.key is 'ArrowRight': next_book(render_book.book_id, 1) ev.preventDefault(), ev.stopPropagation() + elif ev.key is 'Escape': + ev.preventDefault(), ev.stopPropagation() + close_action() def init(container_id): @@ -629,7 +632,7 @@ def init(container_id): create_top_bar(container, title=_('Book details'), action=close_action, icon=close_icon) window.scrollTo(0, 0) # Ensure we are at the top of the window container.appendChild(E.div(class_=CLASS_NAME, tabindex='0')) - container.lastChild.addEventListener('keydown', onkeydown.bind(None, container_id), {'passive': False, 'capture': True}) + container.lastChild.addEventListener('keydown', onkeydown.bind(None, container_id, close_action), {'passive': False, 'capture': True}) container.lastChild.focus() container.lastChild.appendChild(E.div(_('Loading books from the calibre library, please wait...'), style='margin: 1ex 1em')) conditional_timeout(container_id, 5, check_for_books_loaded) diff --git a/src/pyj/book_list/edit_metadata.pyj b/src/pyj/book_list/edit_metadata.pyj index 2177722a1a..afd91450bc 100644 --- a/src/pyj/book_list/edit_metadata.pyj +++ b/src/pyj/book_list/edit_metadata.pyj @@ -1040,10 +1040,18 @@ def check_for_books_loaded(): create_edit_metadata(container) +def handle_keypress(container_id, ev): + if not ev.altKey and not ev.ctrlKey and not ev.metaKey and not ev.shiftKey: + if ev.key is 'Escape': + ev.preventDefault(), ev.stopPropagation() + on_close(container_id) + + def init(container_id): container = document.getElementById(container_id) create_top_bar(container, title=_('Edit metadata'), action=on_close.bind(None, container_id), icon='close') - container.appendChild(E.div(class_=CLASS_NAME)) + container.appendChild(E.div(class_=CLASS_NAME, tabindex='0', onkeydown=handle_keypress.bind(None, container_id))) + container.lastChild.focus() container.lastChild.appendChild(E.div(_('Loading books from the calibre library, please wait...'), style='margin: 1ex 1em')) conditional_timeout(container_id, 5, check_for_books_loaded)