Tweak completion quoting behaviour once again
Quote by wrapping in quotes if we are replacing the whole token, using backspaces if the completion only adds to it. This ensure that the inserted completion will be correctly parsed once validated. Fixes #4121
This commit is contained in:
parent
c507863a00
commit
d1e19727ff
|
@ -669,16 +669,18 @@ Completions CommandManager::complete(const Context& context,
|
||||||
const auto& token = tokens.back();
|
const auto& token = tokens.back();
|
||||||
|
|
||||||
auto requote = [](Completions completions, Token::Type token_type) {
|
auto requote = [](Completions completions, Token::Type token_type) {
|
||||||
if ((completions.flags & Completions::Flags::Quoted) or
|
if (completions.flags & Completions::Flags::Quoted)
|
||||||
completions.start != 0)
|
|
||||||
return completions;
|
return completions;
|
||||||
|
|
||||||
if (token_type == Token::Type::Raw)
|
if (token_type == Token::Type::Raw)
|
||||||
{
|
{
|
||||||
for (auto& c : completions.candidates)
|
const bool at_token_start = completions.start == 0;
|
||||||
|
for (auto& candidate : completions.candidates)
|
||||||
{
|
{
|
||||||
if (c.substr(0_byte, 1_byte) == "%" or any_of(c, [](auto i) { return contains("; \t'\"", i); }))
|
const StringView to_escape = ";\n \t";
|
||||||
c = quote(c);
|
if ((at_token_start and candidate.substr(0_byte, 1_byte) == "%") or
|
||||||
|
any_of(candidate, [&](auto c) { return contains(to_escape, c); }))
|
||||||
|
candidate = at_token_start ? quote(candidate) : escape(candidate, to_escape, '\\');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (token_type == Token::Type::RawQuoted)
|
else if (token_type == Token::Type::RawQuoted)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user