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)

This commit is contained in:
Kovid Goyal 2020-03-25 14:56:31 +05:30
parent f6f418fcb0
commit 779f674aa8
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -208,7 +208,8 @@ class ModeBox(QComboBox):
'''Select how the search expression is interpreted
<dl>
<dt><b>Normal</b></dt>
<dd>The search expression is treated as normal text, calibre will look for the exact text.</dd>
<dd>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.</dd>
<dt><b>Regex</b></dt>
<dd>The search expression is interpreted as a regular expression. See the User Manual for more help on using regular expressions.</dd>
<dt><b>Regex-function</b></dt>
@ -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