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.
This commit is contained in:
parent
0f8b298fad
commit
b1aaf0f10f
@ -30,7 +30,7 @@ from PyQt5.QtWidgets import QLabel, QSizePolicy
|
|||||||
from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt
|
from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt
|
||||||
|
|
||||||
from qutebrowser.config import config, style
|
from qutebrowser.config import config, style
|
||||||
from qutebrowser.utils import objreg, utils
|
from qutebrowser.utils import objreg, utils, usertypes
|
||||||
|
|
||||||
|
|
||||||
class KeyHintView(QLabel):
|
class KeyHintView(QLabel):
|
||||||
@ -67,6 +67,9 @@ class KeyHintView(QLabel):
|
|||||||
style.set_register_stylesheet(self)
|
style.set_register_stylesheet(self)
|
||||||
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Minimum)
|
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Minimum)
|
||||||
self.hide()
|
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):
|
def __repr__(self):
|
||||||
return utils.get_repr(self, win_id=self._win_id)
|
return utils.get_repr(self, win_id=self._win_id)
|
||||||
@ -91,6 +94,7 @@ class KeyHintView(QLabel):
|
|||||||
prefix: The current partial keystring.
|
prefix: The current partial keystring.
|
||||||
"""
|
"""
|
||||||
if not prefix or not self._enabled:
|
if not prefix or not self._enabled:
|
||||||
|
self._show_timer.stop()
|
||||||
self.hide()
|
self.hide()
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -100,9 +104,11 @@ class KeyHintView(QLabel):
|
|||||||
if k.startswith(prefix) and not utils.is_special_key(k)]
|
if k.startswith(prefix) and not utils.is_special_key(k)]
|
||||||
|
|
||||||
if not bindings:
|
if not bindings:
|
||||||
|
self._show_timer.stop()
|
||||||
return
|
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'))
|
suffix_color = html.escape(config.get('colors', 'keyhint.fg.suffix'))
|
||||||
|
|
||||||
text = ''
|
text = ''
|
||||||
|
@ -118,4 +118,5 @@ def test_no_matches(keyhint, key_config_stub):
|
|||||||
('aa', 'cmd-aa'),
|
('aa', 'cmd-aa'),
|
||||||
('ab', 'cmd-ab')]))
|
('ab', 'cmd-ab')]))
|
||||||
keyhint.update_keyhint('normal', 'z')
|
keyhint.update_keyhint('normal', 'z')
|
||||||
|
assert not keyhint.text()
|
||||||
assert not keyhint.isVisible()
|
assert not keyhint.isVisible()
|
||||||
|
Loading…
Reference in New Issue
Block a user