From 52641e25f5d3cc00e34359a7ca6afc7b3e1d040c Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Mon, 16 May 2016 12:57:13 -0400 Subject: [PATCH 1/5] Show currently bound keys in command completion. The command completion menu now uses the misc colum to show a comma-separated list of normal-mode keybindings for each command. --- qutebrowser/completion/models/miscmodels.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/qutebrowser/completion/models/miscmodels.py b/qutebrowser/completion/models/miscmodels.py index 62267d51c..917b09661 100644 --- a/qutebrowser/completion/models/miscmodels.py +++ b/qutebrowser/completion/models/miscmodels.py @@ -19,6 +19,7 @@ """Misc. CompletionModels.""" +from collections import defaultdict from PyQt5.QtCore import Qt, QTimer, pyqtSlot from qutebrowser.browser import webview @@ -32,6 +33,8 @@ class CommandCompletionModel(base.BaseCompletionModel): """A CompletionModel filled with all commands and descriptions.""" + COLUMN_WIDTHS = (20, 60, 20) + # https://github.com/The-Compiler/qutebrowser/issues/545 # pylint: disable=abstract-method @@ -48,8 +51,14 @@ class CommandCompletionModel(base.BaseCompletionModel): for name, cmd in config.section('aliases').items(): cmdlist.append((name, "Alias for '{}'".format(cmd))) cat = self.new_category("Commands") + + # map each command to its bound keys and show these in the misc column + keyconf = objreg.get('key-config') + cmd_to_keys = defaultdict(lambda: []) + for key, cmd in keyconf.get_bindings_for('normal').items(): + cmd_to_keys[cmd].append(key) for (name, desc) in sorted(cmdlist): - self.new_item(cat, name, desc) + self.new_item(cat, name, desc, str.join(',', cmd_to_keys[name])) class HelpCompletionModel(base.BaseCompletionModel): From 06caee41b87e5297d664e6a6c5da27f9251f4c09 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Wed, 18 May 2016 07:46:27 -0400 Subject: [PATCH 2/5] Clean up command_binding_completion. - Add a space after the comman for multiple binding suggestions. - Use defaultdict(list) instead of defaultdict(lambda: []) - Move the pylint comment back to the top of the class --- qutebrowser/completion/models/miscmodels.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qutebrowser/completion/models/miscmodels.py b/qutebrowser/completion/models/miscmodels.py index 917b09661..08cba8c58 100644 --- a/qutebrowser/completion/models/miscmodels.py +++ b/qutebrowser/completion/models/miscmodels.py @@ -33,11 +33,11 @@ class CommandCompletionModel(base.BaseCompletionModel): """A CompletionModel filled with all commands and descriptions.""" - COLUMN_WIDTHS = (20, 60, 20) - # https://github.com/The-Compiler/qutebrowser/issues/545 # pylint: disable=abstract-method + COLUMN_WIDTHS = (20, 60, 20) + def __init__(self, parent=None): super().__init__(parent) assert cmdutils.cmd_dict @@ -54,11 +54,11 @@ class CommandCompletionModel(base.BaseCompletionModel): # map each command to its bound keys and show these in the misc column keyconf = objreg.get('key-config') - cmd_to_keys = defaultdict(lambda: []) + cmd_to_keys = defaultdict(list) for key, cmd in keyconf.get_bindings_for('normal').items(): cmd_to_keys[cmd].append(key) for (name, desc) in sorted(cmdlist): - self.new_item(cat, name, desc, str.join(',', cmd_to_keys[name])) + self.new_item(cat, name, desc, str.join(', ', cmd_to_keys[name])) class HelpCompletionModel(base.BaseCompletionModel): From c050b4973b47786538a8514d00a394bc25655bc8 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Wed, 18 May 2016 07:54:06 -0400 Subject: [PATCH 3/5] Show special keys last in command completion. When showing the currently bound key in the misc column for command completion, if the command has multiple bindings, show special bindings (e.g. ) after non-special bindings. --- qutebrowser/completion/models/miscmodels.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/qutebrowser/completion/models/miscmodels.py b/qutebrowser/completion/models/miscmodels.py index 08cba8c58..99904d1f4 100644 --- a/qutebrowser/completion/models/miscmodels.py +++ b/qutebrowser/completion/models/miscmodels.py @@ -56,7 +56,11 @@ class CommandCompletionModel(base.BaseCompletionModel): keyconf = objreg.get('key-config') cmd_to_keys = defaultdict(list) for key, cmd in keyconf.get_bindings_for('normal').items(): - cmd_to_keys[cmd].append(key) + # put special bindings last + if key.startswith('<') and key.endswith('>'): + cmd_to_keys[cmd].append(key) + else: + cmd_to_keys[cmd].insert(0, key) for (name, desc) in sorted(cmdlist): self.new_item(cat, name, desc, str.join(', ', cmd_to_keys[name])) From 0a0f0feaec582e41b12184bdfcc2e0d1e9ed4d2a Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Wed, 18 May 2016 08:00:21 -0400 Subject: [PATCH 4/5] Update command completions when keyconf changes. When a user changes keybindings, update the command completion model so the new keybindings are shown. --- qutebrowser/completion/models/instances.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qutebrowser/completion/models/instances.py b/qutebrowser/completion/models/instances.py index 1a3a95d3f..30f22ddc5 100644 --- a/qutebrowser/completion/models/instances.py +++ b/qutebrowser/completion/models/instances.py @@ -186,3 +186,7 @@ def init(): history = objreg.get('web-history') history.async_read_done.connect( functools.partial(update, [usertypes.Completion.url])) + + keyconf = objreg.get('key-config') + keyconf.changed.connect( + functools.partial(update, [usertypes.Completion.command])) From 4dd1478d2c6d0cdaec439e00b44b09e9294d7dc0 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Wed, 18 May 2016 08:55:17 -0400 Subject: [PATCH 5/5] Use ', '.join instead of str.join(', ', ...). --- qutebrowser/completion/models/miscmodels.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qutebrowser/completion/models/miscmodels.py b/qutebrowser/completion/models/miscmodels.py index 99904d1f4..831243312 100644 --- a/qutebrowser/completion/models/miscmodels.py +++ b/qutebrowser/completion/models/miscmodels.py @@ -62,7 +62,7 @@ class CommandCompletionModel(base.BaseCompletionModel): else: cmd_to_keys[cmd].insert(0, key) for (name, desc) in sorted(cmdlist): - self.new_item(cat, name, desc, str.join(', ', cmd_to_keys[name])) + self.new_item(cat, name, desc, ', '.join(cmd_to_keys[name])) class HelpCompletionModel(base.BaseCompletionModel):