Add timeout after auto-followed hint
This commit is contained in:
parent
b759f481c4
commit
6e494605dd
@ -893,6 +893,11 @@ class HintManager(QObject):
|
|||||||
elif (len(visible) == 1 and
|
elif (len(visible) == 1 and
|
||||||
config.get('hints', 'auto-follow') and
|
config.get('hints', 'auto-follow') and
|
||||||
filterstr is not None):
|
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.
|
# unpacking gets us the first (and only) key in the dict.
|
||||||
self.fire(*visible)
|
self.fire(*visible)
|
||||||
|
|
||||||
|
@ -913,6 +913,11 @@ def data(readonly=False):
|
|||||||
"Follow a hint immediately when the hint text is completely "
|
"Follow a hint immediately when the hint text is completely "
|
||||||
"matched."),
|
"matched."),
|
||||||
|
|
||||||
|
('auto-follow-timeout',
|
||||||
|
SettingValue(typ.Int(), 0),
|
||||||
|
"A timeout to inhibit normal-mode key bindings after a successful"
|
||||||
|
"auto-follow."),
|
||||||
|
|
||||||
('next-regexes',
|
('next-regexes',
|
||||||
SettingValue(typ.RegexList(flags=re.IGNORECASE),
|
SettingValue(typ.RegexList(flags=re.IGNORECASE),
|
||||||
r'\bnext\b,\bmore\b,\bnewer\b,\b[>→≫]\b,\b(>>|»)\b,'
|
r'\bnext\b,\bmore\b,\bnewer\b,\b[>→≫]\b,\b(>>|»)\b,'
|
||||||
|
@ -49,6 +49,9 @@ class NormalKeyParser(keyparser.CommandKeyParser):
|
|||||||
self.read_config('normal')
|
self.read_config('normal')
|
||||||
self._partial_timer = usertypes.Timer(self, 'partial-match')
|
self._partial_timer = usertypes.Timer(self, 'partial-match')
|
||||||
self._partial_timer.setSingleShot(True)
|
self._partial_timer.setSingleShot(True)
|
||||||
|
self._inhibited = False
|
||||||
|
self._inhibited_timer = usertypes.Timer(self, 'normal-inhibited')
|
||||||
|
self._inhibited_timer.setSingleShot(True)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return utils.get_repr(self)
|
return utils.get_repr(self)
|
||||||
@ -63,6 +66,10 @@ class NormalKeyParser(keyparser.CommandKeyParser):
|
|||||||
A self.Match member.
|
A self.Match member.
|
||||||
"""
|
"""
|
||||||
txt = e.text().strip()
|
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):
|
if not self._keystring and any(txt == c for c in STARTCHARS):
|
||||||
message.set_cmd_text(self._win_id, txt)
|
message.set_cmd_text(self._win_id, txt)
|
||||||
return self.Match.definitive
|
return self.Match.definitive
|
||||||
@ -75,6 +82,15 @@ class NormalKeyParser(keyparser.CommandKeyParser):
|
|||||||
self._partial_timer.start()
|
self._partial_timer.start()
|
||||||
return match
|
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()
|
@pyqtSlot()
|
||||||
def _clear_partial_match(self):
|
def _clear_partial_match(self):
|
||||||
"""Clear a partial keystring after a timeout."""
|
"""Clear a partial keystring after a timeout."""
|
||||||
@ -83,6 +99,12 @@ class NormalKeyParser(keyparser.CommandKeyParser):
|
|||||||
self._keystring = ''
|
self._keystring = ''
|
||||||
self.keystring_updated.emit(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()
|
@pyqtSlot()
|
||||||
def _stop_timers(self):
|
def _stop_timers(self):
|
||||||
super()._stop_timers()
|
super()._stop_timers()
|
||||||
@ -92,6 +114,12 @@ class NormalKeyParser(keyparser.CommandKeyParser):
|
|||||||
except TypeError:
|
except TypeError:
|
||||||
# no connections
|
# no connections
|
||||||
pass
|
pass
|
||||||
|
self._inhibited_timer.stop()
|
||||||
|
try:
|
||||||
|
self._inhibited_timer.timeout.disconnect(self._clear_inhibited)
|
||||||
|
except TypeError:
|
||||||
|
# no connections
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class PromptKeyParser(keyparser.CommandKeyParser):
|
class PromptKeyParser(keyparser.CommandKeyParser):
|
||||||
|
Loading…
Reference in New Issue
Block a user