From 5689a3c0dc9aecae425a9a43602823418a0927f9 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 4 Nov 2017 15:15:58 +0100 Subject: [PATCH] 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 --- qutebrowser/config/config.py | 2 +- tests/unit/config/test_config.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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: