Implement "Current" completion for bind.

When binding a key, the first row will be the current binding if the key
is already bound. This should make it easier for users to tell when they
are binding a key that is already bound, and what it is bound to.
This commit is contained in:
Ryan Roden-Corrent 2017-06-29 21:44:44 -04:00
parent 1e489325c4
commit c1f5e77fc6
2 changed files with 12 additions and 3 deletions

View File

@ -120,14 +120,20 @@ def buffer():
return model
def bind(_key):
def bind(key):
"""A CompletionModel filled with all bindable commands and descriptions.
Args:
_key: the key being bound.
key: the key being bound.
"""
# TODO: offer a 'Current binding' completion based on the key.
model = completionmodel.CompletionModel(column_widths=(20, 60, 20))
cmd_name = objreg.get('key-config').get_bindings_for('normal').get(key)
if cmd_name:
cmd = cmdutils.cmd_dict.get(cmd_name)
data = [(cmd_name, cmd.desc, key)]
model.add_category(listcategory.ListCategory("Current", data))
cmdlist = _get_cmd_completions(include_hidden=True, include_aliases=True)
model.add_category(listcategory.ListCategory("Commands", cmdlist))
return model

View File

@ -567,6 +567,9 @@ def test_bind_completion(qtmodeltester, monkeypatch, stubs, config_stub,
qtmodeltester.check(model)
_check_completions(model, {
"Current": [
('stop', 'stop qutebrowser', 's'),
],
"Commands": [
('drop', 'drop all user data', ''),
('hide', '', ''),