mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-09 09:16:45 +02:00
Viewer: Allow leading and trailing whitespace in search expressions
This commit is contained in:
parent
33fed39269
commit
17b812ea31
1 changed files with 10 additions and 4 deletions
|
|
@ -56,8 +56,10 @@ def stop(self):
|
|||
|
||||
|
||||
def text_to_regex(text):
|
||||
has_leading = text.lstrip() != text
|
||||
has_trailing = text.rstrip() != text
|
||||
ans = []
|
||||
for wpart in spat.split(text):
|
||||
for wpart in spat.split(text.strip()):
|
||||
if not wpart.strip():
|
||||
ans.append(r'\s+')
|
||||
else:
|
||||
|
|
@ -67,6 +69,10 @@ def text_to_regex(text):
|
|||
ans.append('[' + r + ']')
|
||||
else:
|
||||
ans.append(regex.escape(part))
|
||||
if has_leading:
|
||||
ans.insert(0, r'\s+')
|
||||
if has_trailing:
|
||||
ans.append(r'\s+')
|
||||
return ''.join(ans)
|
||||
|
||||
|
||||
|
|
@ -282,14 +288,14 @@ def history_saved(self, new_text, history):
|
|||
vprefs['saved-search-settings'] = sss
|
||||
|
||||
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:
|
||||
sss = vprefs.get('saved-search-settings') or {}
|
||||
sss[text] = {'case_sensitive': self.case_sensitive.isChecked(), 'mode': self.query_type.currentData()}
|
||||
vprefs['saved-search-settings'] = sss
|
||||
|
||||
def saved_search_selected(self):
|
||||
text = self.search_box.currentText().strip()
|
||||
text = self.search_box.currentText()
|
||||
if text:
|
||||
s = (vprefs.get('saved-search-settings') or {}).get(text)
|
||||
if s:
|
||||
|
|
@ -304,7 +310,7 @@ def saved_search_selected(self):
|
|||
self.find_next()
|
||||
|
||||
def search_query(self, backwards=False):
|
||||
text = self.search_box.currentText().strip()
|
||||
text = self.search_box.currentText()
|
||||
if text:
|
||||
return Search(
|
||||
text, self.query_type.currentData() or 'normal',
|
||||
|
|
|
|||
Loading…
Reference in a new issue