mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Add a whole words mode to the viewer search
This commit is contained in:
parent
999626f07a
commit
88109ad655
@ -70,6 +70,12 @@ class Search(object):
|
|||||||
if not self.case_sensitive:
|
if not self.case_sensitive:
|
||||||
flags = regex.IGNORECASE
|
flags = regex.IGNORECASE
|
||||||
if self.mode != 'regex':
|
if self.mode != 'regex':
|
||||||
|
if self.mode == 'word':
|
||||||
|
words = []
|
||||||
|
for part in expr.split():
|
||||||
|
words.append(r'\b{}\b'.format(regex.escape(part)))
|
||||||
|
expr = r'\s+'.join(words)
|
||||||
|
else:
|
||||||
expr = regex.escape(expr)
|
expr = regex.escape(expr)
|
||||||
self._regex = regex.compile(expr, flags)
|
self._regex = regex.compile(expr, flags)
|
||||||
return self._regex
|
return self._regex
|
||||||
@ -206,10 +212,12 @@ class SearchInput(QWidget): # {{{
|
|||||||
self.query_type = qt = QComboBox(self)
|
self.query_type = qt = QComboBox(self)
|
||||||
qt.setFocusPolicy(Qt.NoFocus)
|
qt.setFocusPolicy(Qt.NoFocus)
|
||||||
qt.addItem(_('Normal'), 'normal')
|
qt.addItem(_('Normal'), 'normal')
|
||||||
|
qt.addItem(_('Whole words'), 'word')
|
||||||
qt.addItem(_('Regex'), 'regex')
|
qt.addItem(_('Regex'), 'regex')
|
||||||
qt.setToolTip(textwrap.fill(_('Choose the type of search: Normal will search'
|
qt.setToolTip(textwrap.fill(_('Choose the type of search: Normal will search'
|
||||||
' for the entered text, Regex will interpret the text as a'
|
' for the entered text, Whole words will search for whole words that'
|
||||||
' regular expression')))
|
' equal the entered text and Regex will interpret the text as a'
|
||||||
|
' regular expression.')))
|
||||||
qt.setCurrentIndex(qt.findData(vprefs.get('viewer-search-mode', 'normal') or 'normal'))
|
qt.setCurrentIndex(qt.findData(vprefs.get('viewer-search-mode', 'normal') or 'normal'))
|
||||||
h.addWidget(qt)
|
h.addWidget(qt)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user