mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
a75aea2346
commit
8841a9201b
@ -169,9 +169,11 @@ def searchable_text_for_name(name):
|
|||||||
ans = []
|
ans = []
|
||||||
serialized_data = json.loads(get_data(name)[0])
|
serialized_data = json.loads(get_data(name)[0])
|
||||||
stack = []
|
stack = []
|
||||||
|
removed_tails = []
|
||||||
for child in serialized_data['tree']['c']:
|
for child in serialized_data['tree']['c']:
|
||||||
if child.get('n') == 'body':
|
if child.get('n') == 'body':
|
||||||
stack.append(child)
|
stack.append(child)
|
||||||
|
removed_tails.append((child.pop('l', None), child))
|
||||||
ignore_text = {'script', 'style', 'title'}
|
ignore_text = {'script', 'style', 'title'}
|
||||||
text_pos = 0
|
text_pos = 0
|
||||||
anchor_offset_map = OrderedDict()
|
anchor_offset_map = OrderedDict()
|
||||||
@ -200,6 +202,9 @@ def searchable_text_for_name(name):
|
|||||||
stack.append(tail)
|
stack.append(tail)
|
||||||
if children:
|
if children:
|
||||||
stack.extend(reversed(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
|
return ''.join(ans), anchor_offset_map
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user