From 8841a9201b7d777eb8c33e3bce190f36d131af9d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 16 Jan 2022 04:31:55 +0530 Subject: [PATCH] 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) --- src/calibre/gui2/viewer/search.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/calibre/gui2/viewer/search.py b/src/calibre/gui2/viewer/search.py index 7ec08af0d7..a1f4e85f59 100644 --- a/src/calibre/gui2/viewer/search.py +++ b/src/calibre/gui2/viewer/search.py @@ -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