From 8fd371d83682d7f42cbd6068ab1d8c0733b50e7f Mon Sep 17 00:00:00 2001 From: adam Date: Wed, 27 Apr 2016 16:47:36 -0400 Subject: [PATCH 1/2] Proposed addition for issue #1386 --- qutebrowser/commands/runners.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/qutebrowser/commands/runners.py b/qutebrowser/commands/runners.py index a0851c1b3..963f855ab 100644 --- a/qutebrowser/commands/runners.py +++ b/qutebrowser/commands/runners.py @@ -172,6 +172,20 @@ class CommandRunner(QObject): return self.parse(new_cmd, aliases=False, fallback=fallback, keep=keep) try: + + """ If the command given has only one completion match, replace + the given command with the match. + Ex: If they type "bac" and the only completion is "back", + turn the command into "back". + """ + + matches = [] + for valid_command in cmdutils.cmd_dict.keys(): + if valid_command.find(cmdstr) == 0: + matches.append(valid_command) + if len(matches) == 1: + cmdstr = matches[0] + cmd = cmdutils.cmd_dict[cmdstr] except KeyError: if fallback: From 5eea9d0605b9f85b319d10e450cc994164521d9a Mon Sep 17 00:00:00 2001 From: adam Date: Thu, 28 Apr 2016 09:20:16 -0400 Subject: [PATCH 2/2] Cleanup for flake8/pylint --- qutebrowser/commands/runners.py | 34 +++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/qutebrowser/commands/runners.py b/qutebrowser/commands/runners.py index 963f855ab..a1220864a 100644 --- a/qutebrowser/commands/runners.py +++ b/qutebrowser/commands/runners.py @@ -171,21 +171,10 @@ class CommandRunner(QObject): log.commands.debug("Re-parsing with '{}'.".format(new_cmd)) return self.parse(new_cmd, aliases=False, fallback=fallback, keep=keep) - try: - - """ If the command given has only one completion match, replace - the given command with the match. - Ex: If they type "bac" and the only completion is "back", - turn the command into "back". - """ - matches = [] - for valid_command in cmdutils.cmd_dict.keys(): - if valid_command.find(cmdstr) == 0: - matches.append(valid_command) - if len(matches) == 1: - cmdstr = matches[0] - + cmdstr = self._completion_match(cmdstr) + + try: cmd = cmdutils.cmd_dict[cmdstr] except KeyError: if fallback: @@ -209,6 +198,23 @@ class CommandRunner(QObject): cmdline = [cmdstr] + args[:] return ParseResult(cmd=cmd, args=args, cmdline=cmdline, count=count) + def _completion_match(self, cmdstr): + """Replace cmdstr with a matching completion if there's only one match. + + Args: + cmdstr: The string representing the entered command so far + + Return: + cmdstr modified to the matching completion or unmodified + """ + matches = [] + for valid_command in cmdutils.cmd_dict.keys(): + if valid_command.find(cmdstr) == 0: + matches.append(valid_command) + if len(matches) == 1: + cmdstr = matches[0] + return cmdstr + def _split_args(self, cmd, argstr, keep): """Split the arguments from an arg string.