From d87a1bb2b4920579bd0ccc7643ee2d781fa7ad71 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 10 Mar 2015 21:19:47 +0100 Subject: [PATCH] Add a hints -> scatter option. This is enabled by default to keep the same default behaviour which is like Vimium - mixing e.g. single-char letters and double-char letters, and scattering/shuffling the labels to have an uniform hint key distribution. If disabled, the behaviour is more similiar to dwb, which has a fixed hint string length and simply fills the string starting with the first possible hint char. --- doc/help/settings.asciidoc | 12 ++++++++++++ qutebrowser/browser/hints.py | 28 +++++++++++++++++++++++++++- qutebrowser/config/configdata.py | 5 +++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index 5f038e64b..a3bcac21e 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -150,6 +150,7 @@ |<>|Mode to use for hints. |<>|Chars used for hint strings. |<>|Mininum number of chars used for hint strings. +|<>|Whether to scatter hint key chains (like Vimium) or not (like dwb). |<>|Make chars in hint strings uppercase. |<>|Whether to auto-follow a hint if there's only one left. |<>|A comma-separated list of regexes to use for 'next' links. @@ -1237,6 +1238,17 @@ Mininum number of chars used for hint strings. Default: +pass:[1]+ +[[hints-scatter]] +=== scatter +Whether to scatter hint key chains (like Vimium) or not (like dwb). + +Valid values: + + * +true+ + * +false+ + +Default: +pass:[true]+ + [[hints-uppercase]] === uppercase Make chars in hint strings uppercase. diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py index 30b13355c..af1ba657f 100644 --- a/qutebrowser/browser/hints.py +++ b/qutebrowser/browser/hints.py @@ -202,8 +202,20 @@ class HintManager(QObject): chars = '0123456789' else: chars = config.get('hints', 'chars') - min_chars = config.get('hints', 'min-chars') + if config.get('hints', 'scatter'): + return self._hint_scattered(min_chars, chars, elems) + else: + return self._hint_linear(min_chars, chars, elems) + + def _hint_scattered(self, min_chars, chars, elems): + """Produce scattered hint labels with variable length (like Vimium). + + Args: + min_chars: The minimum length of labels. + chars: The alphabet to use for labels. + elems: The elements to generate labels for. + """ # Determine how many digits the link hints will require in the worst # case. Usually we do not need all of these digits for every link # single hint, so we can show shorter hints for a few of the links. @@ -230,6 +242,20 @@ class HintManager(QObject): return self._shuffle_hints(strings, len(chars)) + def _hint_linear(self, min_chars, chars, elems): + """Produce linear hint labels with constant length (like dwb). + + Args: + min_chars: The minimum length of labels. + chars: The alphabet to use for labels. + elems: The elements to generate labels for. + """ + strings = [] + needed = max(min_chars, math.ceil(math.log(len(elems), len(chars)))) + for i in range(len(elems)): + strings.append(self._number_to_hint_str(i, chars, needed)) + return strings + def _shuffle_hints(self, hints, length): """Shuffle the given set of hints so that they're scattered. diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index e87e49476..6ab5908ab 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -627,6 +627,11 @@ DATA = collections.OrderedDict([ SettingValue(typ.Int(minval=1), '1'), "Mininum number of chars used for hint strings."), + ('scatter', + SettingValue(typ.Bool(), 'true'), + "Whether to scatter hint key chains (like Vimium) or not (like " + "dwb)."), + ('uppercase', SettingValue(typ.Bool(), 'false'), "Make chars in hint strings uppercase."),