Make completion work more or less

This commit is contained in:
Florian Bruhin 2014-11-06 08:26:01 +01:00
parent ac61422059
commit 5fe04a6aec
3 changed files with 19 additions and 11 deletions

View File

@ -217,18 +217,20 @@ class CommandRunner(QObject):
self._cmd = cmdutils.cmd_dict[cmdstr] self._cmd = cmdutils.cmd_dict[cmdstr]
except KeyError: except KeyError:
if fallback: if fallback:
# FIXME test this
cmdstr, sep, argstr = text.partition(' ') cmdstr, sep, argstr = text.partition(' ')
return [cmdstr + sep] + argstr.split(' ') return [cmdstr, sep] + argstr.split(' ')
else: else:
raise cmdexc.NoSuchCommandError( raise cmdexc.NoSuchCommandError(
'{}: no such command'.format(cmdstr)) '{}: no such command'.format(cmdstr))
self._split_args(argstr, keep) self._split_args(argstr, keep)
retargs = self._args[:] retargs = self._args[:]
if keep: if keep and retargs:
cmd = [cmdstr + sep] return [cmdstr, sep + retargs[0]] + retargs[1:]
elif keep:
return [cmdstr, sep]
else: else:
cmd = [cmdstr] return [cmdstr] + retargs
return cmd + retargs
def _split_args(self, argstr, keep): def _split_args(self, argstr, keep):
"""Split the arguments from an arg string. """Split the arguments from an arg string.

View File

@ -174,9 +174,12 @@ class Completer(QObject):
Return: Return:
A completion model. A completion model.
""" """
if parts[cursor_part].startswith('-'): try:
# cursor on a flag if parts[cursor_part].startswith('-'):
return # cursor on a flag
return
except IndexError:
pass
parts, cursor_part = self._filter_cmdline_parts(parts, cursor_part) parts, cursor_part = self._filter_cmdline_parts(parts, cursor_part)
if cursor_part == 0: if cursor_part == 0:
# '|' or 'set|' # '|' or 'set|'
@ -302,7 +305,10 @@ class Completer(QObject):
self._parts)) self._parts))
return 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) self._model().set_pattern(pattern)
log.completion.debug( log.completion.debug(

View File

@ -211,7 +211,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
including a trailing space and we shouldn't continue including a trailing space and we shouldn't continue
completing the current item. completing the current item.
""" """
parts = self.split() parts = self.split(keep=True)
log.completion.debug("changing part {} to '{}'".format( log.completion.debug("changing part {} to '{}'".format(
self._cursor_part, newtext)) self._cursor_part, newtext))
parts[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 # If we should complete immediately, we want to move the cursor by
# one more char, to get to the next field. # one more char, to get to the next field.
cursor_str += ' ' cursor_str += ' '
text = self.prefix() + ' '.join(parts) text = self.prefix() + ''.join(parts)
if immediate and self._cursor_part == len(parts) - 1: if immediate and self._cursor_part == len(parts) - 1:
# If we should complete immediately and we're completing the last # If we should complete immediately and we're completing the last
# part in the commandline, we automatically add a space. # part in the commandline, we automatically add a space.