From a68f997d959223a1a6995b3cb7eb5339ebe0962f Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Wed, 22 Mar 2017 21:44:51 -0400 Subject: [PATCH] Make keyhint delay configurable. ui.keyhint-delay controls the time from starting a keychain to showing the keyhint dialog. Resolves #2462. --- qutebrowser/config/configdata.py | 4 ++++ qutebrowser/misc/keyhintwidget.py | 2 +- tests/unit/misc/test_keyhints.py | 24 ++++++++++++++++++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 25520157d..1fbc22937 100644 --- 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 index c66712eb9..d32b24eb9 100644 --- a/qutebrowser/misc/keyhintwidget.py +++ b/qutebrowser/misc/keyhintwidget.py @@ -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')) diff --git a/tests/unit/misc/test_keyhints.py b/tests/unit/misc/test_keyhints.py index a4093382c..34eea85b5 100644 --- 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