From 5ce9010cc314875065efcc5f708543b4ad0016e5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 1 Sep 2020 20:08:10 +0530 Subject: [PATCH] Store current toc node information when creating highlights --- src/pyj/read_book/annotations.pyj | 6 +++++- src/pyj/read_book/selection_bar.pyj | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/pyj/read_book/annotations.pyj b/src/pyj/read_book/annotations.pyj index f1102db45e..a7126ac52e 100644 --- a/src/pyj/read_book/annotations.pyj +++ b/src/pyj/read_book/annotations.pyj @@ -237,7 +237,7 @@ class AnnotationsManager: # {{{ x = 2 * (spine_index + 1) return f'epubcfi(/{x}{h.start_cfi})' - def add_highlight(self, msg, style, notes): + def add_highlight(self, msg, style, notes, toplevel_toc_node, toc_node): now = Date().toISOString() for uuid in msg.removed_highlights: self.remove_highlight(uuid) @@ -255,6 +255,10 @@ class AnnotationsManager: # {{{ } if notes: annot.notes = notes + if toplevel_toc_node?.title: + annot.top_level_section_title = toplevel_toc_node.title + if toc_node?.title: + annot.lowest_level_section_title = toc_node.title self.sync_annots_to_server('highlights') def highlights_for_currently_showing(self): diff --git a/src/pyj/read_book/selection_bar.pyj b/src/pyj/read_book/selection_bar.pyj index 30faf7bc72..e9ce649ec1 100644 --- a/src/pyj/read_book/selection_bar.pyj +++ b/src/pyj/read_book/selection_bar.pyj @@ -965,7 +965,8 @@ class SelectionBar: _('Highlighting failed'), _('Failed to apply highlighting, try adjusting extent of highlight') ) - self.annotations_manager.add_highlight(msg, self.current_highlight_style.style, notes) + self.annotations_manager.add_highlight( + msg, self.current_highlight_style.style, notes, self.view.current_toc_toplevel_node, self.view.current_toc_node) elif msg.type is 'edit-highlight': if self.state is WAITING: self.create_highlight()