Always prefer exact over partial matches

This commit is contained in:
Florian Bruhin 2018-03-04 21:43:24 +01:00
parent 40c3295cd1
commit e2f17c4be1
2 changed files with 18 additions and 2 deletions

View File

@ -102,14 +102,17 @@ class BaseKeyParser(QObject):
"""
assert sequence
assert not isinstance(sequence, str)
result = QKeySequence.NoMatch
for seq, cmd in self.bindings.items():
assert not isinstance(seq, str), seq
match = sequence.matches(seq)
if match != QKeySequence.NoMatch:
if match == QKeySequence.ExactMatch:
return (match, cmd)
elif match == QKeySequence.PartialMatch:
result = QKeySequence.PartialMatch
return (QKeySequence.NoMatch, None)
return (result, None)
def handle(self, e):
"""Handle a new keypress.

View File

@ -203,6 +203,19 @@ class TestHandle:
keyparser.execute.assert_called_once_with('yank -s', None)
def test_partial_before_full_match(self, keyparser, fake_keyevent,
config_stub):
"""Make sure full matches always take precedence over partial ones."""
config_stub.val.bindings.commands = {
'normal': {
'ab': 'message-info bar',
'a': 'message-info foo'
}
}
keyparser._read_config('normal')
keyparser.handle(fake_keyevent(Qt.Key_A))
keyparser.execute.assert_called_once_with('message-info foo', None)
class TestCount: