From 6e494605dd888556a90e68b6be7efed4a72af96f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Wed, 16 Dec 2015 19:41:07 +0100 Subject: [PATCH] Add timeout after auto-followed hint --- qutebrowser/browser/hints.py | 5 +++++ qutebrowser/config/configdata.py | 5 +++++ qutebrowser/keyinput/modeparsers.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py index 7b098fd25..28dd004b0 100644 --- a/qutebrowser/browser/hints.py +++ b/qutebrowser/browser/hints.py @@ -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) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 659ef08b2..51e4db8e4 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -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,' diff --git a/qutebrowser/keyinput/modeparsers.py b/qutebrowser/keyinput/modeparsers.py index f8c54d79a..46ba86589 100644 --- a/qutebrowser/keyinput/modeparsers.py +++ b/qutebrowser/keyinput/modeparsers.py @@ -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):