From e2f17c4be10c94331e1b37cc11bf7f10861c1e81 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 4 Mar 2018 21:43:24 +0100 Subject: [PATCH] Always prefer exact over partial matches --- qutebrowser/keyinput/basekeyparser.py | 7 +++++-- tests/unit/keyinput/test_basekeyparser.py | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/qutebrowser/keyinput/basekeyparser.py b/qutebrowser/keyinput/basekeyparser.py index e9347fa7b..901e96b55 100644 --- a/qutebrowser/keyinput/basekeyparser.py +++ b/qutebrowser/keyinput/basekeyparser.py @@ -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. diff --git a/tests/unit/keyinput/test_basekeyparser.py b/tests/unit/keyinput/test_basekeyparser.py index 95860399d..893836335 100644 --- a/tests/unit/keyinput/test_basekeyparser.py +++ b/tests/unit/keyinput/test_basekeyparser.py @@ -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: