set_bindings can now update or replace existing bindings
This commit is contained in:
@@ -642,15 +642,17 @@ class KeyMap(object):
|
||||
self._keymap = None
|
||||
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 = {}
|
||||
def set_bindings(self, bindings, mode='update'):
|
||||
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 or mode == 'replace':
|
||||
self._keymap = new_keymap
|
||||
elif mode == 'update':
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user