mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-07 09:01:38 -04:00
Viewer: Allow leading and trailing whitespace in search expressions
This commit is contained in:
parent
33fed39269
commit
17b812ea31
@ -56,8 +56,10 @@ spat = regex.compile(r'(\s+)')
|
|||||||
|
|
||||||
|
|
||||||
def text_to_regex(text):
|
def text_to_regex(text):
|
||||||
|
has_leading = text.lstrip() != text
|
||||||
|
has_trailing = text.rstrip() != text
|
||||||
ans = []
|
ans = []
|
||||||
for wpart in spat.split(text):
|
for wpart in spat.split(text.strip()):
|
||||||
if not wpart.strip():
|
if not wpart.strip():
|
||||||
ans.append(r'\s+')
|
ans.append(r'\s+')
|
||||||
else:
|
else:
|
||||||
@ -67,6 +69,10 @@ def text_to_regex(text):
|
|||||||
ans.append('[' + r + ']')
|
ans.append('[' + r + ']')
|
||||||
else:
|
else:
|
||||||
ans.append(regex.escape(part))
|
ans.append(regex.escape(part))
|
||||||
|
if has_leading:
|
||||||
|
ans.insert(0, r'\s+')
|
||||||
|
if has_trailing:
|
||||||
|
ans.append(r'\s+')
|
||||||
return ''.join(ans)
|
return ''.join(ans)
|
||||||
|
|
||||||
|
|
||||||
@ -282,14 +288,14 @@ class SearchInput(QWidget): # {{{
|
|||||||
vprefs['saved-search-settings'] = sss
|
vprefs['saved-search-settings'] = sss
|
||||||
|
|
||||||
def save_search_type(self):
|
def save_search_type(self):
|
||||||
text = self.search_box.currentText().strip()
|
text = self.search_box.currentText()
|
||||||
if text and not self.ignore_search_type_changes:
|
if text and not self.ignore_search_type_changes:
|
||||||
sss = vprefs.get('saved-search-settings') or {}
|
sss = vprefs.get('saved-search-settings') or {}
|
||||||
sss[text] = {'case_sensitive': self.case_sensitive.isChecked(), 'mode': self.query_type.currentData()}
|
sss[text] = {'case_sensitive': self.case_sensitive.isChecked(), 'mode': self.query_type.currentData()}
|
||||||
vprefs['saved-search-settings'] = sss
|
vprefs['saved-search-settings'] = sss
|
||||||
|
|
||||||
def saved_search_selected(self):
|
def saved_search_selected(self):
|
||||||
text = self.search_box.currentText().strip()
|
text = self.search_box.currentText()
|
||||||
if text:
|
if text:
|
||||||
s = (vprefs.get('saved-search-settings') or {}).get(text)
|
s = (vprefs.get('saved-search-settings') or {}).get(text)
|
||||||
if s:
|
if s:
|
||||||
@ -304,7 +310,7 @@ class SearchInput(QWidget): # {{{
|
|||||||
self.find_next()
|
self.find_next()
|
||||||
|
|
||||||
def search_query(self, backwards=False):
|
def search_query(self, backwards=False):
|
||||||
text = self.search_box.currentText().strip()
|
text = self.search_box.currentText()
|
||||||
if text:
|
if text:
|
||||||
return Search(
|
return Search(
|
||||||
text, self.query_type.currentData() or 'normal',
|
text, self.query_type.currentData() or 'normal',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user