diff --git a/qutebrowser/commands/runners.py b/qutebrowser/commands/runners.py index 963f855abb0..a1220864a62 100644 --- a/qutebrowser/commands/runners.py +++ b/qutebrowser/commands/runners.py @@ -171,21 +171,10 @@ def parse(self, text, *, aliases=True, fallback=False, keep=False): log.commands.debug("Re-parsing with '{}'.".format(new_cmd)) return self.parse(new_cmd, aliases=False, fallback=fallback, keep=keep) + + cmdstr = self._completion_match(cmdstr) + 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: @@ -209,6 +198,23 @@ def parse(self, text, *, aliases=True, fallback=False, keep=False): 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.