diff options
author | Florian Bruhin <git@the-compiler.org> | 2017-11-04 15:15:58 +0100 |
---|---|---|
committer | Florian Bruhin <git@the-compiler.org> | 2017-11-04 15:22:16 +0100 |
commit | 85d643ff49596e2a222be625e008efc4a47fbf9b (patch) | |
tree | 4a09c3f24e0a734b45cd5c7d9d1139473e751793 | |
parent | 12c35ff8365c368a9464ae5fcac823210d8ae738 (diff) | |
download | qutebrowser-85d643ff49596e2a222be625e008efc4a47fbf9b.tar.gz qutebrowser-85d643ff49596e2a222be625e008efc4a47fbf9b.zip |
Fix unbinding default keys twice
When doing :unbind with a default keybinding the first time, it gets inserted
into bindings.commands with None as value.
When then doing :unbind a second time, instead of just leaving that None value
as-is, we removed it again (because it got treated as a custom binding).
Fixes #3162
(cherry picked from commit 5689a3c0dc9aecae425a9a43602823418a0927f9)
-rw-r--r-- | qutebrowser/config/config.py | 2 | ||||
-rw-r--r-- | tests/unit/config/test_config.py | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index 9f5e39793..f3ea11f40 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -198,7 +198,7 @@ class KeyConfig: bindings_commands = self._config.get_obj('bindings.commands') - if key in val.bindings.commands[mode]: + if val.bindings.commands[mode].get(key, None) is not None: # In custom bindings -> remove it del bindings_commands[mode][key] elif key in val.bindings.default[mode]: diff --git a/tests/unit/config/test_config.py b/tests/unit/config/test_config.py index 2d1de02ef..b609a4255 100644 --- a/tests/unit/config/test_config.py +++ b/tests/unit/config/test_config.py @@ -269,6 +269,22 @@ class TestKeyConfig: match="Can't find binding 'foobar' in normal mode"): key_config_stub.unbind('foobar', mode='normal') + def test_unbound_twice(self, key_config_stub, config_stub, no_bindings): + """Try unbinding an already-unbound default key. + + For custom-bound keys (in bindings.commands), it's okay to display an + error, as this isn't something you'd do in e.g a config.py anyways. + + https://github.com/qutebrowser/qutebrowser/issues/3162 + """ + config_stub.val.bindings.default = {'normal': {'a': 'nop'}} + config_stub.val.bindings.commands = no_bindings + + key_config_stub.unbind('a') + assert key_config_stub.get_command('a', mode='normal') is None + key_config_stub.unbind('a') + assert key_config_stub.get_command('a', mode='normal') is None + class TestConfig: |