E-book viewer: Fix searching for text near the end of a chapter sometimes not working. Fixes #1958028 [ebook-viewer search claims text at end of chapter is "hidden"](https://bugs.launchpad.net/calibre/+bug/1958028)

This commit is contained in:
Kovid Goyal 2022-01-16 04:31:55 +05:30
parent a75aea2346
commit 8841a9201b
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -169,9 +169,11 @@ def searchable_text_for_name(name):
ans = []
serialized_data = json.loads(get_data(name)[0])
stack = []
removed_tails = []
for child in serialized_data['tree']['c']:
if child.get('n') == 'body':
stack.append(child)
removed_tails.append((child.pop('l', None), child))
ignore_text = {'script', 'style', 'title'}
text_pos = 0
anchor_offset_map = OrderedDict()
@ -200,6 +202,9 @@ def searchable_text_for_name(name):
stack.append(tail)
if children:
stack.extend(reversed(children))
for (tail, body) in removed_tails:
if tail is not None:
body['l'] = tail
return ''.join(ans), anchor_offset_map