From 779f674aa82abe113162e4c14022b4b0178c4fed Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 25 Mar 2020 14:56:31 +0530 Subject: [PATCH] Edit book: When searching in normal mode, have spaces in the search expression match multiple spaces and line breaks in the text. Fixes #1868847 [Edit Book Find feature does not find consistently.](https://bugs.launchpad.net/calibre/+bug/1868847) --- src/calibre/gui2/tweak_book/search.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/tweak_book/search.py b/src/calibre/gui2/tweak_book/search.py index 657a57bb26..02cd4d4e5e 100644 --- a/src/calibre/gui2/tweak_book/search.py +++ b/src/calibre/gui2/tweak_book/search.py @@ -208,7 +208,8 @@ class ModeBox(QComboBox): '''Select how the search expression is interpreted
Normal
-
The search expression is treated as normal text, calibre will look for the exact text.
+
The search expression is treated as normal text, calibre will look for the exact text, + except that spaces are allowed to match any number of spaces and line breaks.
Regex
The search expression is interpreted as a regular expression. See the User Manual for more help on using regular expressions.
Regex-function
@@ -1272,7 +1273,8 @@ def get_search_regex(state): raw = state['find'] is_regex = state['mode'] != 'normal' if not is_regex: - raw = regex.escape(raw, special_only=True) + parts = (regex.escape(x, special_only=True) for x in raw.split()) + raw = r'\s+'.join(parts) flags = REGEX_FLAGS if not state['case_sensitive']: flags |= regex.IGNORECASE