mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
E-book viewer: Show an error if the user tries to search for only punctuation or spaces in the search modes that ignore these. Fixes #2015795 [Searching for punctuation freezes the e-book viewer](https://bugs.launchpad.net/calibre/+bug/2015795)
This commit is contained in:
parent
b41e2be8e3
commit
cc89ccb265
@ -145,6 +145,14 @@ class Search:
|
||||
self._nsd = word_pats, full_pat
|
||||
return self._nsd
|
||||
|
||||
@property
|
||||
def is_empty(self):
|
||||
if not self.text:
|
||||
return True
|
||||
if self.mode in ('normal', 'word') and not regex.sub(r'[\s\p{P}]+', '', self.text):
|
||||
return True
|
||||
return False
|
||||
|
||||
def __str__(self):
|
||||
from collections import namedtuple
|
||||
s = ('text', 'mode', 'case_sensitive', 'backwards')
|
||||
|
@ -336,6 +336,9 @@ class EbookViewer(MainWindow):
|
||||
def start_search(self, search_query):
|
||||
name = self.web_view.current_content_file
|
||||
if name:
|
||||
if search_query.is_empty and search_query.text:
|
||||
return error_dialog(self, _('Empty search expression'), _(
|
||||
'Cannot search for {!r} as it contains only punctuation and spaces.').format(search_query.text), show=True)
|
||||
self.web_view.get_current_cfi(self.search_widget.set_anchor_cfi)
|
||||
self.search_widget.start_search(search_query, name)
|
||||
self.web_view.setFocus(Qt.FocusReason.OtherFocusReason)
|
||||
|
Loading…
x
Reference in New Issue
Block a user