From b1aaf0f10f5d93645e1dab562a84f191a9488d74 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Sun, 22 May 2016 07:41:30 -0400 Subject: [PATCH] Only show keyhints after a short delay. If a user knows the keychain and can type it quickly, we shouldn't annoy them with a popup. Only show the keyhint if the user doesn't complete their keychain in 500ms. The isVisible() check in the tests is somewhat invalid now because it is never immediately visible and I don't want to add a delay to unit tests. I added a check that text() is not set for one test that was only checking isVisible(). Addresses part of #1515. --- qutebrowser/misc/keyhintwidget.py | 10 ++++++++-- tests/unit/misc/test_keyhints.py | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/qutebrowser/misc/keyhintwidget.py b/qutebrowser/misc/keyhintwidget.py index c3864c691..192e11893 100644 --- a/qutebrowser/misc/keyhintwidget.py +++ b/qutebrowser/misc/keyhintwidget.py @@ -30,7 +30,7 @@ from PyQt5.QtWidgets import QLabel, QSizePolicy from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt from qutebrowser.config import config, style -from qutebrowser.utils import objreg, utils +from qutebrowser.utils import objreg, utils, usertypes class KeyHintView(QLabel): @@ -67,6 +67,9 @@ class KeyHintView(QLabel): style.set_register_stylesheet(self) 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) def __repr__(self): return utils.get_repr(self, win_id=self._win_id) @@ -91,6 +94,7 @@ class KeyHintView(QLabel): prefix: The current partial keystring. """ if not prefix or not self._enabled: + self._show_timer.stop() self.hide() return @@ -100,9 +104,11 @@ class KeyHintView(QLabel): if k.startswith(prefix) and not utils.is_special_key(k)] if not bindings: + self._show_timer.stop() return - self.show() + # delay so a quickly typed keychain doesn't display hints + self._show_timer.start() suffix_color = html.escape(config.get('colors', 'keyhint.fg.suffix')) text = '' diff --git a/tests/unit/misc/test_keyhints.py b/tests/unit/misc/test_keyhints.py index 2f312e8b3..63e5dc1e9 100644 --- a/tests/unit/misc/test_keyhints.py +++ b/tests/unit/misc/test_keyhints.py @@ -118,4 +118,5 @@ def test_no_matches(keyhint, key_config_stub): ('aa', 'cmd-aa'), ('ab', 'cmd-ab')])) keyhint.update_keyhint('normal', 'z') + assert not keyhint.text() assert not keyhint.isVisible()