summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2024-01-12 18:48:08 +0100
committerFlorian Bruhin <me@the-compiler.org>2024-01-12 18:53:22 +0100
commit6bc140bf713b3de9feedb6689c63a12e5533be3d (patch)
tree3f024141f6540a98bc8248445305aaa62134da70
parentee9aecda46ea610644452d2280cefe3ffd64dcbf (diff)
downloadqutebrowser-6bc140bf713b3de9feedb6689c63a12e5533be3d.tar.gz
qutebrowser-6bc140bf713b3de9feedb6689c63a12e5533be3d.zip
listcategory: Clean up building regex pattern
- Don't split the pattern in weird places used for str.join, instead build up the individual groups and then "".join them, which seems more readable to me. - Don't reuse "val" for both the user-input pattern and the regex pattern.
-rw-r--r--qutebrowser/completion/models/listcategory.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/qutebrowser/completion/models/listcategory.py b/qutebrowser/completion/models/listcategory.py
index 226f5e999..f92679cc6 100644
--- a/qutebrowser/completion/models/listcategory.py
+++ b/qutebrowser/completion/models/listcategory.py
@@ -52,8 +52,9 @@ class ListCategory(QSortFilterProxyModel):
# 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)
+ re_pattern = "^" + "".join(f"(?=.*{re.escape(term)})" for term in val.split())
+
+ rx = QRegularExpression(re_pattern, QRegularExpression.PatternOption.CaseInsensitiveOption)
qtutils.ensure_valid(rx)
self.setFilterRegularExpression(rx)
self.invalidate()