From fe4800b68f01d4ffc90c6ff159b9b316119613f8 Mon Sep 17 00:00:00 2001 From: Felix Van der Jeugt Date: Tue, 5 Apr 2016 09:51:22 +0200 Subject: [PATCH] prevent words from the dictionary prefixing smart hints --- qutebrowser/browser/hints.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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