This commit is contained in:
cryzed 2017-11-08 15:08:36 +01:00
parent b9aa5df5ed
commit 6e719d1796
2 changed files with 11 additions and 0 deletions

View File

@ -170,6 +170,11 @@ class KeyConfig:
def bind(self, key, command, *, mode, save_yaml=False):
"""Add a new binding from key to command."""
if command is not None and not command.strip():
raise configexc.KeybindingError(
"Can't add binding '{}' with empty command in {} "
'mode'.format(key, mode))
key = self._prepare(key, mode)
log.keyboard.vdebug("Adding binding {} -> {} in mode {}.".format(
key, command, mode))

View File

@ -285,6 +285,12 @@ class TestKeyConfig:
key_config_stub.unbind('a')
assert key_config_stub.get_command('a', mode='normal') is None
def test_empty_command(self, key_config_stub):
"""Try binding a key to an empty command."""
message = "Can't add binding 'x' with empty command in normal mode"
with pytest.raises(configexc.KeybindingError, match=message):
key_config_stub.bind('x', ' ', mode='normal')
class TestConfig: