From 06404ae119f5d82d2480484b7f6c3ae43b8333a8 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 13 Sep 2020 10:25:35 +0530 Subject: [PATCH] Workaround for Firefox bug that broke searching backwards across file boundaries. Fixes #1895388 [Private bug](https://bugs.launchpad.net/calibre/+bug/1895388) --- src/pyj/read_book/iframe.pyj | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/pyj/read_book/iframe.pyj b/src/pyj/read_book/iframe.pyj index 869b6506d9..2fcbd2feea 100644 --- a/src/pyj/read_book/iframe.pyj +++ b/src/pyj/read_book/iframe.pyj @@ -703,7 +703,19 @@ class IframeBoss: self.last_search_at = window.performance.now() if data.searched_in_spine: window.getSelection().removeAllRanges() - if window.find(data.text, False, data.backwards, from_load and data.backwards): + wrap_search = from_load and data.backwards + found = window.find(data.text, False, data.backwards, wrap_search) + if not found and wrap_search: + # wrapping is not implemented on Firefox + prev_range = None + while window.find(data.text, False): + prev_range = window.getSelection().getRangeAt(0) + if prev_range: + sel = window.getSelection() + sel.removeAllRanges() + sel.addRange(prev_range) + found = window.find(data.text, False, True) + if found: if current_layout_mode() is not 'flow': snap_to_selection() else: