Repository: qutebrowser/qutebrowser

Issue:
Make keyhint show timeout configurable
The time until the keyhint widget is shown after a keypress is currently hardcoded to 500ms. This should probably be configurable.

cc @rcorre 


Discussion:

Resolving patch:
diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py
--- a/qutebrowser/config/configdata.py
+++ b/qutebrowser/config/configdata.py
@@ -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."),
diff --git a/qutebrowser/misc/keyhintwidget.py b/qutebrowser/misc/keyhintwidget.py
--- a/qutebrowser/misc/keyhintwidget.py
+++ b/qutebrowser/misc/keyhintwidget.py
@@ -67,7 +67,6 @@ def __init__(self, win_id, parent=None):
         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 @@ def blacklisted(keychain):
             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'))
 


Test patch:
diff --git a/tests/unit/misc/test_keyhints.py b/tests/unit/misc/test_keyhints.py
--- a/tests/unit/misc/test_keyhints.py
+++ b/tests/unit/misc/test_keyhints.py
@@ -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