Merge pull request #398 from woorst/missing_bindings

set_bindings can now update or replace existing bindings
This commit is contained in:
Michael Lazar
2017-07-25 00:21:01 -04:00
committed by GitHub
3 changed files with 17 additions and 10 deletions

View File

@@ -643,14 +643,16 @@ class KeyMap(object):
self.set_bindings(bindings)
def set_bindings(self, bindings):
# Clear the keymap before applying the bindings to avoid confusion.
# If a user defines custom bindings in their config file, they must
# explicitly define ALL of the bindings.
self._keymap = {}
new_keymap = {}
for command, keys in bindings.items():
if not isinstance(command, Command):
command = Command(command)
self._keymap[command] = keys
new_keymap[command] = keys
if not self._keymap:
self._keymap = new_keymap
else:
self._keymap.update(new_keymap)
def get(self, command):
if not isinstance(command, Command):
@@ -694,4 +696,4 @@ class KeyMap(object):
except (AttributeError, ValueError, TypeError):
raise exceptions.ConfigError('Invalid configuration! "%s" is not a '
'valid key' % key)
'valid key' % key)