From e40834080ec7ce169f0a454b2833c249f4275ef5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 13 May 2020 14:26:27 +0530 Subject: [PATCH] Viewer/Edit book fuzzy search: Ignore soft hyphens and zero-width joiner characters when searching for text. Fixes #1878046 [[Enhancement] Fuzzy search mode should ignore soft hyphens](https://bugs.launchpad.net/calibre/+bug/1878046) --- src/calibre/gui2/viewer/search.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/viewer/search.py b/src/calibre/gui2/viewer/search.py index dd523f68b4..66668d1e9e 100644 --- a/src/calibre/gui2/viewer/search.py +++ b/src/calibre/gui2/viewer/search.py @@ -20,7 +20,7 @@ from calibre.gui2 import warning_dialog from calibre.gui2.progress_indicator import ProgressIndicator from calibre.gui2.viewer.web_view import get_data, get_manifest, vprefs from calibre.gui2.widgets2 import HistoryComboBox -from polyglot.builtins import iteritems, unicode_type +from polyglot.builtins import iteritems, unicode_type, map from polyglot.functools import lru_cache from polyglot.queue import Queue @@ -53,6 +53,7 @@ class BusySpinner(QWidget): # {{{ quote_map= {'"':'"“”', "'": "'‘’"} qpat = regex.compile(r'''(['"])''') spat = regex.compile(r'(\s+)') +invisible_chars = '(?:[\u00ad\u200d]{0,1})' def text_to_regex(text): @@ -70,7 +71,8 @@ def text_to_regex(text): if r is not None: ans.append('[' + r + ']') else: - ans.append(regex.escape(part)) + part = invisible_chars.join(map(regex.escape, part)) + ans.append(part) if has_leading: ans.insert(0, r'\s+') if has_trailing: