diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 8d7c0c2cf..701c8324f 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -34,7 +34,7 @@ from qutebrowser.commands import userscripts, cmdexc, cmdutils, runners from qutebrowser.config import config, configdata from qutebrowser.browser import (urlmarks, browsertab, inspector, navigate, webelem, downloads) -from qutebrowser.keyinput import modeman +from qutebrowser.keyinput import modeman, keyutils from qutebrowser.utils import (message, usertypes, log, qtutils, urlutils, objreg, utils, standarddir) from qutebrowser.utils.usertypes import KeyMode @@ -2111,17 +2111,15 @@ class CommandDispatcher: keystring: The keystring to send. global_: If given, the keys are sent to the qutebrowser UI. """ - # FIXME: rewrite try: - keyinfos = utils.parse_keystring(keystring) - except utils.KeyParseError as e: + sequence = keyutils.KeySequence.parse(keystring) + except keyutils.KeyParseError as e: raise cmdexc.CommandError(str(e)) - for keyinfo in keyinfos: - press_event = QKeyEvent(QEvent.KeyPress, keyinfo.key, - keyinfo.modifiers, keyinfo.text) - release_event = QKeyEvent(QEvent.KeyRelease, keyinfo.key, - keyinfo.modifiers, keyinfo.text) + for keyinfo in sequence: + args = (keyinfo.key, keyinfo.modifiers, keyinfo.text()) + press_event = QKeyEvent(QEvent.KeyPress, *args) + release_event = QKeyEvent(QEvent.KeyRelease, *args) if global_: window = QApplication.focusWindow() diff --git a/qutebrowser/keyinput/keyutils.py b/qutebrowser/keyinput/keyutils.py index 1e8b3f248..b0b05851a 100644 --- a/qutebrowser/keyinput/keyutils.py +++ b/qutebrowser/keyinput/keyutils.py @@ -251,6 +251,13 @@ class KeyInfo: # "normal" binding return normalized + def text(self): + """Get the text which would be displayed when pressing this key.""" + text = QKeySequence(self.key).toString() + if not self.modifiers & Qt.ShiftModifier: + text = text.lower() + return text + class KeySequence: @@ -327,6 +334,7 @@ class KeySequence: @classmethod def parse(cls, keystr): """Parse a keystring like or xyz and return a KeySequence.""" + # FIXME have multiple sequences in self! s = ', '.join(_parse_keystring(keystr)) new = cls(s) assert len(new) > 0