E-book viewer: Fix indication of current section in Table of Contents sometimes wrong after changing font size. Fixes #2033205 [E-book viewer: incorrect ToC highligting after changing font size](https://bugs.launchpad.net/calibre/+bug/2033205)

This commit is contained in:
Kovid Goyal 2023-09-01 15:59:32 +05:30
parent 8271fcff30
commit e1d8b44561
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 28 additions and 22 deletions

View File

@ -402,7 +402,7 @@ class IframeBoss:
if cfi:
self.jump_to_cfi('/' + cfi)
self.update_cfi()
self.update_toc_position()
self.update_toc_position(True)
def number_of_columns_changed(self, data):
opts.columns_per_screen = data.columns_per_screen
@ -548,8 +548,8 @@ class IframeBoss:
self.send_message(
'update_progress_frac', progress_frac=pf, file_progress_frac=fpf, page_counts=page_counts())
def update_toc_position(self):
visible_anchors = update_visible_toc_anchors(self.book.manifest.toc_anchor_map, self.anchor_funcs)
def update_toc_position(self, recalculate_toc_anchor_positions):
visible_anchors = update_visible_toc_anchors(self.book.manifest.toc_anchor_map, self.anchor_funcs, bool(recalculate_toc_anchor_positions))
self.send_message('update_toc_position', visible_anchors=visible_anchors)
def onscroll(self):

View File

@ -198,10 +198,7 @@ def create_toc_panel(book, container, onclick):
toc_panel.style.flexShrink = '1'
toc_panel.style.overflow = 'auto'
def current_toc_anchor_map(tam, anchor_funcs):
current_map = toc_anchor_map()
if not (current_map and current_map.layout_mode is current_layout_mode() and current_map.width is scroll_viewport.width() and current_map.height is scroll_viewport.height()):
def recalculate_toc_anchor_positions(tam, anchor_funcs):
name = current_spine_item().name
am = {}
anchors = v'[]'
@ -223,7 +220,16 @@ def current_toc_anchor_map(tam, anchor_funcs):
return current_map
def update_visible_toc_anchors(toc_anchor_map, anchor_funcs):
def current_toc_anchor_map(tam, anchor_funcs):
current_map = toc_anchor_map()
if not (current_map and current_map.layout_mode is current_layout_mode() and current_map.width is scroll_viewport.width() and current_map.height is scroll_viewport.height()):
current_map = recalculate_toc_anchor_positions(tam, anchor_funcs)
return current_map
def update_visible_toc_anchors(toc_anchor_map, anchor_funcs, recalculate):
if recalculate:
recalculate_toc_anchor_positions(toc_anchor_map, anchor_funcs)
tam = current_toc_anchor_map(toc_anchor_map, anchor_funcs)
before = after = None
visible_anchors = {}