diff options
| author | Maxime Coste <mawww@kakoune.org> | 2021-03-31 17:15:31 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2021-03-31 17:15:31 +1100 |
| commit | d1e19727ff9d3ae9c90609e4b6a1671f43b15dd6 (patch) | |
| tree | 8f8e829d1e315f3764a89900a5089f1ac9022767 /src/command_manager.cc | |
| parent | c507863a00289fe4b210ecc4fef5554de4c87bf4 (diff) | |
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
Diffstat (limited to 'src/command_manager.cc')
| -rw-r--r-- | src/command_manager.cc | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/command_manager.cc b/src/command_manager.cc index 1e1f2035..cb7ddf82 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -669,16 +669,18 @@ Completions CommandManager::complete(const Context& context, const auto& token = tokens.back(); auto requote = [](Completions completions, Token::Type token_type) { - if ((completions.flags & Completions::Flags::Quoted) or - completions.start != 0) + if (completions.flags & Completions::Flags::Quoted) return completions; 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); })) - c = quote(c); + const StringView to_escape = ";\n \t"; + 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) |
