Fix command-mode completion behavior when input is escaped

If `a\ b.txt` were a local file, `:o a\ <tab>` would fill the prompt
with `:o aa\ b.txt` because the replacement range was calculated using
the shellwords-parsed part. Escaping the part before calculating its
length fixes this edge-case.
This commit is contained in:
Michael Davis 2022-11-03 21:02:26 -05:00 committed by Blaž Hrastnik
parent 3d283b2ca4
commit 140df92d79

View file

@ -2216,12 +2216,15 @@ pub(super) fn command_mode(cx: &mut Context) {
..
}) = typed::TYPABLE_COMMAND_MAP.get(&parts[0] as &str)
{
let part_len = shellwords::escape(part.clone()).len();
completer(editor, part)
.into_iter()
.map(|(range, file)| {
let file = shellwords::escape(file);
// offset ranges to input
let offset = input.len() - part.len();
let offset = input.len() - part_len;
let range = (range.start + offset)..;
(range, file)
})