Improve key parsing with simple keys containing </>

This commit is contained in:
Florian Bruhin 2018-02-27 09:22:11 +01:00
parent 1ba61bbcbe
commit 5d581d42f5

View File

@ -149,6 +149,7 @@ def _parse_keystring(keystr):
special = False special = False
for c in keystr: for c in keystr:
if c == '>': if c == '>':
assert special
yield normalize_keystr(key) yield normalize_keystr(key)
key = '' key = ''
special = False special = False
@ -158,6 +159,10 @@ def _parse_keystring(keystr):
key += c key += c
else: else:
yield 'Shift+' + c if c.isupper() else c yield 'Shift+' + c if c.isupper() else c
if special:
yield '<'
for c in key:
yield 'Shift+' + c if c.isupper() else c
def normalize_keystr(keystr): def normalize_keystr(keystr):
@ -389,6 +394,7 @@ class KeySequence:
@classmethod @classmethod
def parse(cls, keystr): def parse(cls, keystr):
"""Parse a keystring like <Ctrl-x> or xyz and return a KeySequence.""" """Parse a keystring like <Ctrl-x> or xyz and return a KeySequence."""
# FIXME: test stuff like <a, a>
new = cls() new = cls()
strings = list(_parse_keystring(keystr)) strings = list(_parse_keystring(keystr))
for sub in utils.chunk(strings, cls._MAX_LEN): for sub in utils.chunk(strings, cls._MAX_LEN):
@ -396,8 +402,7 @@ class KeySequence:
new._sequences.append(sequence) new._sequences.append(sequence)
if keystr: if keystr:
# FIXME fails with "<ctrl-x" assert len(new) > 0, keystr
assert len(new) > 0
new._validate(keystr) new._validate(keystr)
return new return new