Don't crash Completer on unknown command.
The CommandRunner's fallback parsing behavior treated whitespace differently than the normal flow. When a user entered an unknown command, trailing whitespace would be stripped and the cmdline length would be less than the cursor position. This is fixed by making the fallback use the ShellLexer just as the 'normal' parsing does.
This commit is contained in:
parent
69a3df174d
commit
b867b87955
@ -174,15 +174,6 @@ class CommandRunner(QObject):
|
||||
count = None
|
||||
return (count, cmdstr)
|
||||
|
||||
def _parse_fallback(self, text, count, keep):
|
||||
"""Parse the given commandline without a valid command."""
|
||||
if keep:
|
||||
cmdstr, sep, argstr = text.partition(' ')
|
||||
cmdline = [cmdstr, sep] + argstr.split()
|
||||
else:
|
||||
cmdline = text.split()
|
||||
return ParseResult(cmd=None, args=None, cmdline=cmdline, count=count)
|
||||
|
||||
def parse(self, text, *, fallback=False, keep=False):
|
||||
"""Split the commandline text into command and arguments.
|
||||
|
||||
@ -210,7 +201,9 @@ class CommandRunner(QObject):
|
||||
if not fallback:
|
||||
raise cmdexc.NoSuchCommandError(
|
||||
'{}: no such command'.format(cmdstr))
|
||||
return self._parse_fallback(text, count, keep)
|
||||
cmdline = split.split(text, keep=keep)
|
||||
return ParseResult(cmd=None, args=None, cmdline=cmdline,
|
||||
count=count)
|
||||
|
||||
args = self._split_args(cmd, argstr, keep)
|
||||
if keep and args:
|
||||
|
@ -176,6 +176,7 @@ def _set_cmd_prompt(cmd, txt):
|
||||
usertypes.Completion.command)),
|
||||
(':set -t -p |', usertypes.Completion.section),
|
||||
(':open -- |', None),
|
||||
(':gibberish nonesense |', None),
|
||||
])
|
||||
def test_update_completion(txt, expected, status_command_stub, completer_obj,
|
||||
completion_widget_stub):
|
||||
|
Loading…
Reference in New Issue
Block a user