Filter hints using a multi-word matching

(addresses https://github.com/The-Compiler/qutebrowser/issues/674#issuecomment-165101219 )
This commit is contained in:
Jakub Klinkovský 2015-12-24 12:51:30 +01:00 committed by Florian Bruhin
parent d3eec49b6e
commit e4d5b550a3

View File

@ -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)