Normalize keys read from the config
This makes sure the internal bindings.commands object only contains normalized key sequences. Fixes #3699
This commit is contained in:
parent
990c0707f4
commit
9941812127
@ -1650,6 +1650,9 @@ class Key(BaseType):
|
|||||||
|
|
||||||
"""A name of a key."""
|
"""A name of a key."""
|
||||||
|
|
||||||
|
def from_obj(self, value):
|
||||||
|
return str(keyutils.KeySequence.parse(value))
|
||||||
|
|
||||||
def to_py(self, value):
|
def to_py(self, value):
|
||||||
self._basic_py_validation(value, str)
|
self._basic_py_validation(value, str)
|
||||||
if not value:
|
if not value:
|
||||||
|
@ -339,6 +339,24 @@ class TestKeyConfig:
|
|||||||
key_config_stub.unbind(seq)
|
key_config_stub.unbind(seq)
|
||||||
assert key_config_stub.get_command(seq, mode='normal') is None
|
assert key_config_stub.get_command(seq, mode='normal') is None
|
||||||
|
|
||||||
|
def test_unbind_old_syntax(self, yaml_config_stub, key_config_stub,
|
||||||
|
config_stub):
|
||||||
|
"""Test unbinding bindings added before the keybinding refactoring.
|
||||||
|
|
||||||
|
We used to normalize keys differently, so we can have <ctrl+q> in the
|
||||||
|
config.
|
||||||
|
|
||||||
|
See https://github.com/qutebrowser/qutebrowser/issues/3699
|
||||||
|
"""
|
||||||
|
bindings = {'normal': {'<ctrl+q>': 'nop'}}
|
||||||
|
yaml_config_stub.set_obj('bindings.commands', bindings)
|
||||||
|
config_stub.read_yaml()
|
||||||
|
|
||||||
|
key_config_stub.unbind(keyutils.KeySequence.parse('<ctrl+q>'),
|
||||||
|
save_yaml=True)
|
||||||
|
|
||||||
|
assert config.instance.get_obj('bindings.commands') == {'normal': {}}
|
||||||
|
|
||||||
def test_empty_command(self, key_config_stub):
|
def test_empty_command(self, key_config_stub):
|
||||||
"""Try binding a key to an empty command."""
|
"""Try binding a key to an empty command."""
|
||||||
message = "Can't add binding 'x' with empty command in normal mode"
|
message = "Can't add binding 'x' with empty command in normal mode"
|
||||||
|
Loading…
Reference in New Issue
Block a user