diff --git a/qutebrowser/keyinput/keyutils.py b/qutebrowser/keyinput/keyutils.py index 7f0e669a6..1bd9ee737 100644 --- a/qutebrowser/keyinput/keyutils.py +++ b/qutebrowser/keyinput/keyutils.py @@ -30,6 +30,10 @@ from PyQt5.QtGui import QKeySequence, QKeyEvent from qutebrowser.utils import utils +def is_printable(key): + return key <= 0xff + + def _key_to_string(key): """Convert a Qt::Key member to a meaningful name. @@ -227,7 +231,7 @@ class KeyInfo: key_string = _key_to_string(self.key) - if len(key_string) == 1: + if is_printable(self.key) and self.key != Qt.Key_Space: category = unicodedata.category(key_string) is_special_char = (category == 'Cc') else: @@ -254,8 +258,7 @@ class KeyInfo: """Get the text which would be displayed when pressing this key.""" if self.key == Qt.Key_Space: return ' ' - elif self.key > 0xff: - # Unprintable keys + elif not is_printable(self.key): return '' text = QKeySequence(self.key).toString() @@ -386,7 +389,7 @@ class KeySequence: modifiers = ev.modifiers() if (modifiers == Qt.ShiftModifier and - len(ev.text()) == 1 and + is_printable(ev.key()) and unicodedata.category(ev.text()) != 'Lu'): modifiers = Qt.KeyboardModifiers() diff --git a/qutebrowser/keyinput/modeparsers.py b/qutebrowser/keyinput/modeparsers.py index 42eeb53f8..d56d7dcd1 100644 --- a/qutebrowser/keyinput/modeparsers.py +++ b/qutebrowser/keyinput/modeparsers.py @@ -280,13 +280,12 @@ class RegisterKeyParser(keyparser.CommandKeyParser): if match: return match - key = e.text() - - if key == '' or not str(keyutils.KeyInfo.from_event(e)): + if not keyutils.is_printable(e.key()): # this is not a proper register key, let it pass and keep going - # FIXME can we simplify this when we refactor keyutils.py? return QKeySequence.NoMatch + key = e.text() + tabbed_browser = objreg.get('tabbed-browser', scope='window', window=self._win_id) macro_recorder = objreg.get('macro-recorder')