Add timeout after auto-followed hint

This commit is contained in:
Jakub Klinkovský 2015-12-16 19:41:07 +01:00 committed by Florian Bruhin
parent b759f481c4
commit 6e494605dd
3 changed files with 38 additions and 0 deletions

View File

@ -893,6 +893,11 @@ class HintManager(QObject):
elif (len(visible) == 1 and
config.get('hints', 'auto-follow') and
filterstr is not None):
# apply auto-follow-timeout
timeout = config.get('hints', 'auto-follow-timeout')
man_inst = modeman.instance(self._win_id)
normal_parser = man_inst._parsers[usertypes.KeyMode.normal]
normal_parser.set_inhibited_timeout(timeout)
# unpacking gets us the first (and only) key in the dict.
self.fire(*visible)

View File

@ -913,6 +913,11 @@ def data(readonly=False):
"Follow a hint immediately when the hint text is completely "
"matched."),
('auto-follow-timeout',
SettingValue(typ.Int(), 0),
"A timeout to inhibit normal-mode key bindings after a successful"
"auto-follow."),
('next-regexes',
SettingValue(typ.RegexList(flags=re.IGNORECASE),
r'\bnext\b,\bmore\b,\bnewer\b,\b[>→≫]\b,\b(>>|»)\b,'

View File

@ -49,6 +49,9 @@ class NormalKeyParser(keyparser.CommandKeyParser):
self.read_config('normal')
self._partial_timer = usertypes.Timer(self, 'partial-match')
self._partial_timer.setSingleShot(True)
self._inhibited = False
self._inhibited_timer = usertypes.Timer(self, 'normal-inhibited')
self._inhibited_timer.setSingleShot(True)
def __repr__(self):
return utils.get_repr(self)
@ -63,6 +66,10 @@ class NormalKeyParser(keyparser.CommandKeyParser):
A self.Match member.
"""
txt = e.text().strip()
if self._inhibited is True:
self._debug_log("Ignoring key '{}', because the normal mode is "
"currently inhibited.".format(txt))
return self.Match.none
if not self._keystring and any(txt == c for c in STARTCHARS):
message.set_cmd_text(self._win_id, txt)
return self.Match.definitive
@ -75,6 +82,15 @@ class NormalKeyParser(keyparser.CommandKeyParser):
self._partial_timer.start()
return match
def set_inhibited_timeout(self, timeout):
if timeout != 0:
self._debug_log("Inhibiting the normal mode for {}ms.".format(
timeout))
self._inhibited = True
self._inhibited_timer.setInterval(timeout)
self._inhibited_timer.timeout.connect(self._clear_inhibited)
self._inhibited_timer.start()
@pyqtSlot()
def _clear_partial_match(self):
"""Clear a partial keystring after a timeout."""
@ -83,6 +99,12 @@ class NormalKeyParser(keyparser.CommandKeyParser):
self._keystring = ''
self.keystring_updated.emit(self._keystring)
@pyqtSlot()
def _clear_inhibited(self):
"""Reset inhibition state after a timeout."""
self._debug_log("Releasing inhibition state of normal mode.")
self._inhibited = False
@pyqtSlot()
def _stop_timers(self):
super()._stop_timers()
@ -92,6 +114,12 @@ class NormalKeyParser(keyparser.CommandKeyParser):
except TypeError:
# no connections
pass
self._inhibited_timer.stop()
try:
self._inhibited_timer.timeout.disconnect(self._clear_inhibited)
except TypeError:
# no connections
pass
class PromptKeyParser(keyparser.CommandKeyParser):