Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news.d/bugfix/1850.core.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Treat unbound keys as no-op.
2 changes: 1 addition & 1 deletion plover/machine/keymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def keys_to_actions(self, key_list):
action_list = []
for key in key_list:
assert key in self._keys, "'%s' not in %s" % (key, self._keys)
action = self._bindings[key]
action = self._bindings.get(key, "no-op")
if "no-op" != action:
action_list.append(action)
return action_list
Expand Down
12 changes: 12 additions & 0 deletions test/test_keymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ def test_keymap_set_mappings():
assert k.get_mappings() == MAPPINGS_FULL


def test_keymap_keys_to_actions_for_unbound_key():
# An unbound key is treated as no-op.
k = new_keymap()
k.set_bindings(BINDINGS_DICT)
assert "k2" not in k.get_bindings()
assert k.keys_to_actions(["k0", "k2", "k4"]) == ["a0", "a1"]
# If the machine emits a key out of range, it's an error:
with pytest.raises(AssertionError):
# AssertionError: 'k9' not in OrderedDict({...})
k.keys_to_actions(["k9"])


def test_keymap_setitem():
bindings = dict(BINDINGS_DICT)
mappings = dict(MAPPINGS_FULL)
Expand Down
Loading