From e4d5b550a39496eac9664d907a07d2c221b409bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Thu, 24 Dec 2015 12:51:30 +0100 Subject: [PATCH] Filter hints using a multi-word matching (addresses https://github.com/The-Compiler/qutebrowser/issues/674#issuecomment-165101219 ) --- qutebrowser/browser/hints.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py index bc4990f53..022dcb574 100644 --- a/qutebrowser/browser/hints.py +++ b/qutebrowser/browser/hints.py @@ -724,6 +724,16 @@ class HintManager(QObject): keyparser = keyparsers[usertypes.KeyMode.hint] keyparser.update_bindings(strings, preserve_filter=True) + def _filter_matches(self, filterstr, elemstr): + """Returns True if `filterstr` matches `elemstr`.""" + # Empty string and None always match + if not filterstr: + return True + filterstr = filterstr.casefold() + elemstr = elemstr.casefold() + # Do multi-word matching + return all(word in elemstr for word in filterstr.split()) + def follow_prevnext(self, frame, baseurl, prev=False, tab=False, background=False, window=False): """Click a "previous"/"next" element on the page. @@ -901,8 +911,7 @@ class HintManager(QObject): for elems in self._context.all_elems: try: - if (filterstr is None or - filterstr.casefold() in str(elems.elem).casefold()): + if self._filter_matches(filterstr, str(elems.elem)): if self._is_hidden(elems.label): # hidden element which matches again -> show it self._show_elem(elems.label)