Always prefer exact over partial matches
This commit is contained in:
parent
40c3295cd1
commit
e2f17c4be1
@ -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.
|
||||
|
@ -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:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user