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]
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.

View File

@ -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(

View File

@ -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.