From 5fe04a6aec8cad1326bcb7aa4e6e974b98d8af59 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 6 Nov 2014 08:26:01 +0100 Subject: [PATCH] Make completion work more or less --- qutebrowser/commands/runners.py | 12 +++++++----- qutebrowser/utils/completer.py | 14 ++++++++++---- qutebrowser/widgets/statusbar/command.py | 4 ++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/qutebrowser/commands/runners.py b/qutebrowser/commands/runners.py index 2a0740d96..037f2dd21 100644 --- a/qutebrowser/commands/runners.py +++ b/qutebrowser/commands/runners.py @@ -217,18 +217,20 @@ class CommandRunner(QObject): self._cmd = cmdutils.cmd_dict[cmdstr] except KeyError: if fallback: + # FIXME test this cmdstr, sep, argstr = text.partition(' ') - return [cmdstr + sep] + argstr.split(' ') + return [cmdstr, sep] + argstr.split(' ') else: raise cmdexc.NoSuchCommandError( '{}: no such command'.format(cmdstr)) self._split_args(argstr, keep) retargs = self._args[:] - if keep: - cmd = [cmdstr + sep] + if keep and retargs: + return [cmdstr, sep + retargs[0]] + retargs[1:] + elif keep: + return [cmdstr, sep] else: - cmd = [cmdstr] - return cmd + retargs + return [cmdstr] + retargs def _split_args(self, argstr, keep): """Split the arguments from an arg string. diff --git a/qutebrowser/utils/completer.py b/qutebrowser/utils/completer.py index cdb682815..5875ec70c 100644 --- a/qutebrowser/utils/completer.py +++ b/qutebrowser/utils/completer.py @@ -174,9 +174,12 @@ class Completer(QObject): Return: A completion model. """ - if parts[cursor_part].startswith('-'): - # cursor on a flag - return + try: + if parts[cursor_part].startswith('-'): + # cursor on a flag + return + except IndexError: + pass parts, cursor_part = self._filter_cmdline_parts(parts, cursor_part) if cursor_part == 0: # '|' or 'set|' @@ -302,7 +305,10 @@ class Completer(QObject): self._parts)) return - pattern = self._parts[self._cursor_part] if self._parts else '' + try: + pattern = self._parts[self._cursor_part] if self._parts else '' + except IndexError: + pattern = '' self._model().set_pattern(pattern) log.completion.debug( diff --git a/qutebrowser/widgets/statusbar/command.py b/qutebrowser/widgets/statusbar/command.py index 81b75b2ab..38364d710 100644 --- a/qutebrowser/widgets/statusbar/command.py +++ b/qutebrowser/widgets/statusbar/command.py @@ -211,7 +211,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): including a trailing space and we shouldn't continue completing the current item. """ - parts = self.split() + parts = self.split(keep=True) log.completion.debug("changing part {} to '{}'".format( self._cursor_part, newtext)) parts[self._cursor_part] = newtext @@ -221,7 +221,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): # If we should complete immediately, we want to move the cursor by # one more char, to get to the next field. cursor_str += ' ' - text = self.prefix() + ' '.join(parts) + text = self.prefix() + ''.join(parts) if immediate and self._cursor_part == len(parts) - 1: # If we should complete immediately and we're completing the last # part in the commandline, we automatically add a space.