Fix handling of empty bindings without breaking :unbind

1899e313fd as a fix for #3631 broke :unbind, as
the config system treats None and '' equally.

Instead, allow None/'' again, but just handle it as "no binding".
This commit is contained in:
Florian Bruhin 2018-03-08 11:41:31 +01:00
parent 1899e313fd
commit 482b622b1b
5 changed files with 17 additions and 3 deletions

View File

@ -134,7 +134,7 @@ Fixed
- HTML/JS resource files are now read into RAM on start to avoid crashes when
changing qutebrowser versions while it's open.
- Setting `bindings.key_mappings` to an empty value is now allowed.
- Binding to an empty command now shows an error rather than crashing.
- Bindings to an empty commands are now ignored rather than crashing.
Removed
~~~~~~~

View File

@ -147,7 +147,7 @@ class KeyConfig:
"""Get the combined bindings for the given mode."""
bindings = dict(val.bindings.default[mode])
for key, binding in val.bindings.commands[mode].items():
if binding is None:
if not binding:
bindings.pop(key, None)
else:
bindings[key] = binding

View File

@ -2485,7 +2485,9 @@ bindings.commands:
name: Dict
none_ok: true
keytype: Key
valtype: Command
valtype:
name: Command
none_ok: true # needed for :unbind
desc: >-
Keybindings mapping keys to commands in different modes.

View File

@ -161,6 +161,12 @@ class TestKeyConfig:
for key, command in expected.items():
assert key_config_stub.get_command(key, 'normal') == command
def test_get_bindings_for_empty_command(self, key_config_stub,
config_stub):
config_stub.val.bindings.commands = {'normal': {',x': ''}}
bindings = key_config_stub.get_bindings_for('normal')
assert keyseq(',x') not in bindings
def test_get_command_unbound(self, key_config_stub, config_stub,
no_bindings):
config_stub.val.bindings.default = no_bindings

View File

@ -115,6 +115,12 @@ class TestReadConfig:
assert keyseq('foo') in keyparser.bindings
assert keyseq('<ctrl+x>') in keyparser.bindings
def test_read_config_empty_binding(self, keyparser, config_stub):
"""Make sure setting an empty binding doesn't crash."""
keyparser._read_config('normal')
config_stub.val.bindings.commands = {'normal': {'co': ''}}
# The config is re-read automatically
def test_read_config_modename_none(self, keyparser):
assert keyparser._modename is None