Fix bind completion for bindings with arguments.

When a key is bound to a command line that includes one or more
arguments to a command, bind completion should show the whole command
for the "Current" category, and use only the command name to look up the
description.

Fixes #2859, where a crash was caused by looking up the description by
the full command text rather than just the name.
This commit is contained in:
Ryan Roden-Corrent 2017-07-25 12:55:44 -04:00
parent 79e7eb6495
commit 1929883485
2 changed files with 7 additions and 6 deletions

View File

@ -126,11 +126,12 @@ def bind(key):
key: the key being bound. key: the key being bound.
""" """
model = completionmodel.CompletionModel(column_widths=(20, 60, 20)) model = completionmodel.CompletionModel(column_widths=(20, 60, 20))
cmd_name = objreg.get('key-config').get_bindings_for('normal').get(key) cmd_text = objreg.get('key-config').get_bindings_for('normal').get(key)
if cmd_name: if cmd_text:
cmd_name = cmd_text.split(' ')[0]
cmd = cmdutils.cmd_dict.get(cmd_name) cmd = cmdutils.cmd_dict.get(cmd_name)
data = [(cmd_name, cmd.desc, key)] data = [(cmd_text, cmd.desc, key)]
model.add_category(listcategory.ListCategory("Current", data)) model.add_category(listcategory.ListCategory("Current", data))
cmdlist = _get_cmd_completions(include_hidden=True, include_aliases=True) cmdlist = _get_cmd_completions(include_hidden=True, include_aliases=True)

View File

@ -583,7 +583,7 @@ def test_bind_completion(qtmodeltester, monkeypatch, stubs, config_stub,
_patch_cmdutils(monkeypatch, stubs, _patch_cmdutils(monkeypatch, stubs,
'qutebrowser.completion.models.miscmodels.cmdutils') 'qutebrowser.completion.models.miscmodels.cmdutils')
config_stub.data['aliases'] = {'rock': 'roll'} config_stub.data['aliases'] = {'rock': 'roll'}
key_config_stub.set_bindings_for('normal', {'s': 'stop', key_config_stub.set_bindings_for('normal', {'s': 'stop now',
'rr': 'roll', 'rr': 'roll',
'ro': 'rock'}) 'ro': 'rock'})
model = miscmodels.bind('s') model = miscmodels.bind('s')
@ -593,14 +593,14 @@ def test_bind_completion(qtmodeltester, monkeypatch, stubs, config_stub,
_check_completions(model, { _check_completions(model, {
"Current": [ "Current": [
('stop', 'stop qutebrowser', 's'), ('stop now', 'stop qutebrowser', 's'),
], ],
"Commands": [ "Commands": [
('drop', 'drop all user data', ''), ('drop', 'drop all user data', ''),
('hide', '', ''), ('hide', '', ''),
('rock', "Alias for 'roll'", 'ro'), ('rock', "Alias for 'roll'", 'ro'),
('roll', 'never gonna give you up', 'rr'), ('roll', 'never gonna give you up', 'rr'),
('stop', 'stop qutebrowser', 's'), ('stop', 'stop qutebrowser', ''),
] ]
}) })