From c1f5e77fc69a3c23000416f7c9907dd2bf3e958d Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Thu, 29 Jun 2017 21:44:44 -0400 Subject: [PATCH] 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. --- qutebrowser/completion/models/miscmodels.py | 12 +++++++++--- tests/unit/completion/test_models.py | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/qutebrowser/completion/models/miscmodels.py b/qutebrowser/completion/models/miscmodels.py index 0af6060e7..00fabb031 100644 --- a/qutebrowser/completion/models/miscmodels.py +++ b/qutebrowser/completion/models/miscmodels.py @@ -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 diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index 959224398..b7b688a81 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -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', '', ''),