diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py index 9ec14388f..b821e43c7 100644 --- a/qutebrowser/browser/hints.py +++ b/qutebrowser/browser/hints.py @@ -1068,12 +1068,16 @@ class WordHinter: return any(hint.startswith(e) or e.startswith(hint) for e in existing) - def new_hint_for(self, elem, existing): + def filter_prefixes(self, hints, existing): + return (h for h in hints if not self.any_prefix(h, existing)) + + def new_hint_for(self, elem, existing, fallback): """Return a hint for elem, not conflicting with the existing.""" new = self.tag_words_to_hints(self.extract_tag_words(elem)) - no_prefixes = (h for h in new if not self.any_prefix(h, existing)) + new_no_prefixes = self.filter_prefixes(new, existing) + fallback_no_prefixes = self.filter_prefixes(fallback, existing) # either the first good, or None - return next(no_prefixes, None) + return next(new_no_prefixes, next(fallback_no_prefixes)) def hint(self, elems): """Produce hint labels based on the html tags. @@ -1093,7 +1097,7 @@ class WordHinter: used_hints = set() words = iter(self.words) for elem in elems: - hint = self.new_hint_for(elem, used_hints) or next(words) + hint = self.new_hint_for(elem, used_hints, words) used_hints.add(hint) hints.append(hint) return hints