Make mode optionally in ConfigAPI.bind and .unbind
This commit is contained in:
parent
a23492fe27
commit
7d1549aaeb
@ -162,6 +162,8 @@ To bind a key:
|
||||
config.bind(',v', 'spawn mpv {url}', mode='normal')
|
||||
----
|
||||
|
||||
For bindings in normal mode, you can also leave out the `, mode='normal'` part.
|
||||
|
||||
If the key is already bound, `force=True` needs to be given to rebind it:
|
||||
|
||||
[source,python]
|
||||
|
@ -180,11 +180,11 @@ class ConfigAPI:
|
||||
with self._handle_error('setting', name):
|
||||
self._config.set_obj(name, value)
|
||||
|
||||
def bind(self, key, command, *, mode, force=False):
|
||||
def bind(self, key, command, *, mode='normal', force=False):
|
||||
with self._handle_error('binding', key):
|
||||
self._keyconfig.bind(key, command, mode=mode, force=force)
|
||||
|
||||
def unbind(self, key, *, mode):
|
||||
def unbind(self, key, *, mode='normal'):
|
||||
with self._handle_error('unbinding', key):
|
||||
self._keyconfig.unbind(key, mode=mode)
|
||||
|
||||
|
@ -191,16 +191,24 @@ class TestConfigPy:
|
||||
configfiles.read_config_py(confpy.filename)
|
||||
assert config.instance._values['colors.hints.bg'] == expected
|
||||
|
||||
def test_bind(self, confpy):
|
||||
confpy.write('config.bind(",a", "message-info foo", mode="normal")')
|
||||
@pytest.mark.parametrize('line, mode', [
|
||||
('config.bind(",a", "message-info foo")', 'normal'),
|
||||
('config.bind(",a", "message-info foo", "prompt")', 'prompt'),
|
||||
])
|
||||
def test_bind(self, confpy, line, mode):
|
||||
confpy.write(line)
|
||||
configfiles.read_config_py(confpy.filename)
|
||||
expected = {'normal': {',a': 'message-info foo'}}
|
||||
expected = {mode: {',a': 'message-info foo'}}
|
||||
assert config.instance._values['bindings.commands'] == expected
|
||||
|
||||
def test_unbind(self, confpy):
|
||||
confpy.write('config.unbind("o", mode="normal")')
|
||||
@pytest.mark.parametrize('line, key, mode', [
|
||||
('config.unbind("o")', 'o', 'normal'),
|
||||
('config.unbind("y", mode="prompt")', 'y', 'prompt'),
|
||||
])
|
||||
def test_unbind(self, confpy, line, key, mode):
|
||||
confpy.write(line)
|
||||
configfiles.read_config_py(confpy.filename)
|
||||
expected = {'normal': {'o': None}}
|
||||
expected = {mode: {key: None}}
|
||||
assert config.instance._values['bindings.commands'] == expected
|
||||
|
||||
def test_mutating(self, confpy):
|
||||
|
Loading…
Reference in New Issue
Block a user