Make keyhint delay configurable.

ui.keyhint-delay controls the time from starting a keychain to showing the
keyhint dialog. Resolves #2462.
This commit is contained in:
Ryan Roden-Corrent 2017-03-22 21:44:51 -04:00
parent 0c7d012420
commit a68f997d95
3 changed files with 27 additions and 3 deletions

View File

@ -406,6 +406,10 @@ def data(readonly=False):
"Globs are supported, so ';*' will blacklist all keychains"
"starting with ';'. Use '*' to disable keyhints"),
('keyhint-delay',
SettingValue(typ.Int(minval=0), '500'),
"Time from pressing a key to seeing the keyhint dialog (ms)"),
('prompt-radius',
SettingValue(typ.Int(minval=0), '8'),
"The rounding radius for the edges of prompts."),

View File

@ -67,7 +67,6 @@ class KeyHintView(QLabel):
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Minimum)
self.hide()
self._show_timer = usertypes.Timer(self, 'keyhint_show')
self._show_timer.setInterval(500)
self._show_timer.timeout.connect(self.show)
style.set_register_stylesheet(self)
@ -108,6 +107,7 @@ class KeyHintView(QLabel):
return
# delay so a quickly typed keychain doesn't display hints
self._show_timer.setInterval(config.get('ui', 'keyhint-delay'))
self._show_timer.start()
suffix_color = html.escape(config.get('colors', 'keyhint.fg.suffix'))

View File

@ -44,8 +44,8 @@ def expected_text(*args):
@pytest.fixture
def keyhint(qtbot, config_stub, key_config_stub):
"""Fixture to initialize a KeyHintView."""
def keyhint_config(config_stub):
"""Fixture providing the necessary config settings for the KeyHintView."""
config_stub.data = {
'colors': {
'keyhint.fg': 'white',
@ -55,9 +55,16 @@ def keyhint(qtbot, config_stub, key_config_stub):
'fonts': {'keyhint': 'Comic Sans'},
'ui': {
'keyhint-blacklist': '',
'keyhint-delay': 500,
'status-position': 'bottom',
},
}
return config_stub
@pytest.fixture
def keyhint(qtbot, keyhint_config, key_config_stub):
"""Fixture to initialize a KeyHintView."""
keyhint = KeyHintView(0, None)
qtbot.add_widget(keyhint)
assert keyhint.text() == ''
@ -161,3 +168,16 @@ def test_blacklist_all(keyhint, config_stub, key_config_stub):
keyhint.update_keyhint('normal', 'a')
assert not keyhint.text()
def test_delay(qtbot, stubs, monkeypatch, keyhint_config, key_config_stub):
timer = stubs.FakeTimer()
monkeypatch.setattr(
'qutebrowser.misc.keyhintwidget.usertypes.Timer',
lambda *_: timer)
interval = 200
keyhint_config.set('ui', 'keyhint-delay', interval)
key_config_stub.set_bindings_for('normal', OrderedDict([('aa', 'cmd-aa')]))
keyhint = KeyHintView(0, None)
keyhint.update_keyhint('normal', 'a')
assert timer.interval() == interval