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.
This commit is contained in:
parent
2f0522ebb0
commit
d87a1bb2b4
@ -150,6 +150,7 @@
|
||||
|<<hints-mode,mode>>|Mode to use for hints.
|
||||
|<<hints-chars,chars>>|Chars used for hint strings.
|
||||
|<<hints-min-chars,min-chars>>|Mininum number of chars used for hint strings.
|
||||
|<<hints-scatter,scatter>>|Whether to scatter hint key chains (like Vimium) or not (like dwb).
|
||||
|<<hints-uppercase,uppercase>>|Make chars in hint strings uppercase.
|
||||
|<<hints-auto-follow,auto-follow>>|Whether to auto-follow a hint if there's only one left.
|
||||
|<<hints-next-regexes,next-regexes>>|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.
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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."),
|
||||
|
Loading…
Reference in New Issue
Block a user