Merge pull request #7955 from arza-zara/search_any_order
A few more completions will now match search terms in any order: `:quickmark-*`, `:bookmark-*`, `:tab-take` and `:tab-select` (for the quick and bookmark categories).
This commit is contained in:
commit
fe1faa14b9
|
|
@ -48,9 +48,11 @@ class ListCategory(QSortFilterProxyModel):
|
|||
log.completion.warning(f"Trimming {len(val)}-char pattern to 5000")
|
||||
val = val[:5000]
|
||||
self._pattern = val
|
||||
val = re.sub(r' +', r' ', val) # See #1919
|
||||
val = re.escape(val)
|
||||
val = val.replace(r'\ ', '.*')
|
||||
|
||||
# Positive lookahead per search term. This means that all search terms must
|
||||
# be matched but they can be matched anywhere in the string, so they can be
|
||||
# in any order. For example "foo bar" -> "(?=.*foo)(?=.*bar)"
|
||||
val = '(?=.*' + ')(?=.*'.join(map(re.escape, val.split())) + ')'
|
||||
rx = QRegularExpression(val, QRegularExpression.PatternOption.CaseInsensitiveOption)
|
||||
qtutils.ensure_valid(rx)
|
||||
self.setFilterRegularExpression(rx)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,11 @@ from qutebrowser.completion.models import listcategory
|
|||
[('foo', 'bar'), ('bar', 'foo'), ('bar', 'bar')],
|
||||
[('foo', 'bar'), ('bar', 'foo')],
|
||||
[('foo', 'bar'), ('bar', 'foo')]),
|
||||
|
||||
('foo bar',
|
||||
[('foobar', ''), ('barfoo', ''), ('foobaz', '')],
|
||||
[('barfoo', ''), ('foobar', '')],
|
||||
[('foobar', ''), ('barfoo', '')]),
|
||||
])
|
||||
def test_set_pattern(pattern, before, after, after_nosort, model_validator):
|
||||
"""Validate the filtering and sorting results of set_pattern."""
|
||||
|
|
|
|||
Loading…
Reference in New Issue