From a74a9c8a215615d9e900054dc7b20c716303b7ce Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 13 May 2015 07:54:06 +0200 Subject: [PATCH] Fix adding of new default section to keyconf. When trying to add a new binding with multiple values, the bindings were added immediately and the next _is_new() check returned False because the command was already bound. With this change, the new bindings first get added to a temporary dict so _is_new() returns the correct result. See #653. --- qutebrowser/config/parsers/keyconf.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/qutebrowser/config/parsers/keyconf.py b/qutebrowser/config/parsers/keyconf.py index b15a9ae4a..059ea5cdc 100644 --- a/qutebrowser/config/parsers/keyconf.py +++ b/qutebrowser/config/parsers/keyconf.py @@ -237,20 +237,31 @@ class KeyConfigParser(QObject): only_new: If set, only keybindings which are completely unused (same command/key not bound) are added. """ + + # {'sectname': {'keychain1': 'command', 'keychain2': 'command'}, ...} + bindings_to_add = collections.OrderedDict() + for sectname, sect in configdata.KEY_DATA.items(): sectname = self._normalize_sectname(sectname) + bindings_to_add[sectname] = collections.OrderedDict() + for command, keychains in sect.items(): + for e in keychains: + if not only_new or self._is_new(sectname, command, e): + assert e not in bindings_to_add[sectname] + bindings_to_add[sectname][e] = command + + for sectname, sect in bindings_to_add.items(): if not sect: if not only_new: self.keybindings[sectname] = collections.OrderedDict() - self._mark_config_dirty() else: - for command, keychains in sect.items(): - for e in keychains: - if not only_new or self._is_new(sectname, command, e): - self._add_binding(sectname, e, command) - self._mark_config_dirty() + for keychain, command in sect.items(): + self._add_binding(sectname, keychain, command) self.changed.emit(sectname) + if bindings_to_add: + self._mark_config_dirty() + def _is_new(self, sectname, command, keychain): """Check if a given binding is new.