From ee8ba55676de14eeaca08ac5c27621ce859eaa62 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 21 Apr 2014 17:17:34 +0200 Subject: [PATCH] Support esc to abort hinting --- qutebrowser/app.py | 2 ++ qutebrowser/browser/curcommand.py | 5 +++++ qutebrowser/browser/hints.py | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index ab4f216d6..69fe2e9e8 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -242,6 +242,8 @@ class QuteBrowser(QApplication): self.mainwindow.status.keystring.setText) self._keyparsers["hint"].fire_hint.connect( self.mainwindow.tabs.cur.fire_hint) + self._keyparsers["hint"].abort_hinting.connect( + self.mainwindow.tabs.cur.abort_hinting) self._keyparsers["hint"].keystring_updated.connect( self.mainwindow.tabs.cur.handle_hint_key) self.mainwindow.tabs.hint_strings_updated.connect( diff --git a/qutebrowser/browser/curcommand.py b/qutebrowser/browser/curcommand.py index 16ad97d35..ec0c94254 100644 --- a/qutebrowser/browser/curcommand.py +++ b/qutebrowser/browser/curcommand.py @@ -185,6 +185,11 @@ class CurCommandDispatcher(QObject): """Fire a completed hint.""" self._tabs.currentWidget().hintmanager.fire(keystr) + @pyqtSlot() + def abort_hinting(self): + """Abort hinting.""" + self._tabs.currentWidget().hintmanager.stop() + @pyqtSlot(str, int) def search(self, text, flags): """Search for text in the current page. diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py index c1deb4bc7..b81673ced 100644 --- a/qutebrowser/browser/hints.py +++ b/qutebrowser/browser/hints.py @@ -41,10 +41,20 @@ class HintKeyParser(KeyParser): Signals: fire_hint: When a hint keybinding was completed. Arg: the keystring/hint string pressed. + abort_hinting: Esc pressed, so abort hinting. """ supports_count = False fire_hint = pyqtSignal(str) + abort_hinting = pyqtSignal() + + def _handle_modifier_key(self, e): + """We don't support modifiers here, but we'll handle escape in here.""" + if e.key() == Qt.Key_Escape: + self._keystring = '' + self.abort_hinting.emit() + return True + return False def execute(self, cmdstr, count=None): """Handle a completed keychain."""