From dc41e4e30e6b1cb9261f7a4901172bdb5a51a09a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 8 Mar 2021 20:18:32 +0530 Subject: [PATCH] Fix #1918054 [[Enhancement - Content server viewer] Clicking Esc to go back in the Highlight page doesn't work if one highlight is selected](https://bugs.launchpad.net/calibre/+bug/1918054) --- src/pyj/read_book/highlights.pyj | 13 +++++++++---- src/pyj/read_book/overlay.pyj | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/pyj/read_book/highlights.pyj b/src/pyj/read_book/highlights.pyj index d0c4564cf0..b574fa5758 100644 --- a/src/pyj/read_book/highlights.pyj +++ b/src/pyj/read_book/highlights.pyj @@ -808,7 +808,7 @@ def delete_selection(annotations_manager, view): ) -def highlight_entry(h, onclick, view): +def highlight_entry(h, onclick, view, hide_panel): def action(func, ev): ev.stopPropagation(), ev.preventDefault() @@ -828,7 +828,12 @@ def highlight_entry(h, onclick, view): class_='title-row', E.div(class_='title', swatch, E.div(style='margin-left: 1rem', h.highlighted_text)), E.div(style='margin-left: 1rem', onclick=def(ev): ev.stopPropagation();, - E.input(type='checkbox', onchange=item_select_toggled)), + E.input(type='checkbox', onchange=item_select_toggled, onkeydown=def(ev): + if ev.key is 'Escape': + ev.stopPropagation() + ev.preventDefault() + hide_panel() + )), ), E.div( class_='actions', @@ -847,7 +852,7 @@ def highlight_entry(h, onclick, view): return ans -def create_highlights_panel(annotations_manager, book, container, onclick): +def create_highlights_panel(annotations_manager, hide_panel, book, container, onclick): next_button = E.div(class_='simple-link ac-button', svgicon('chevron-down'), title=_('Next match')) prev_button = E.div(class_='simple-link ac-button', svgicon('chevron-up'), title=_('Previous match')) prev_button.addEventListener('click', def(ev): find_previous();) @@ -917,5 +922,5 @@ def create_highlights_panel(annotations_manager, book, container, onclick): c.appendChild(g) ic = g.lastChild for h in highlights: - ic.appendChild(highlight_entry(h, onclick, annotations_manager.view)) + ic.appendChild(highlight_entry(h, onclick, annotations_manager.view, hide_panel)) # }}} diff --git a/src/pyj/read_book/overlay.pyj b/src/pyj/read_book/overlay.pyj index 9327e57f40..3bc91edb10 100644 --- a/src/pyj/read_book/overlay.pyj +++ b/src/pyj/read_book/overlay.pyj @@ -720,7 +720,7 @@ class Overlay: self.hide() ui_operations.toggle_highlights() return - self.panels.push(TOCOverlay(self, create_highlights_panel.bind(None, self.view.annotations_manager), _('Highlights'))) + self.panels.push(TOCOverlay(self, create_highlights_panel.bind(None, self.view.annotations_manager, self.hide_current_panel), _('Highlights'))) self.show_current_panel() def show_goto(self):