From 6bc140bf713b3de9feedb6689c63a12e5533be3d Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 12 Jan 2024 18:48:08 +0100 Subject: 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. --- qutebrowser/completion/models/listcategory.py | 5 +++-- 1 file 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() -- cgit v1.2.3-54-g00ecf