From 140df92d7936e1fd036128d98ab565d92e9d2bd8 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Thu, 3 Nov 2022 21:02:26 -0500 Subject: [PATCH] Fix command-mode completion behavior when input is escaped If `a\ b.txt` were a local file, `:o a\ ` 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. --- helix-term/src/commands/typed.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 36080d392..2f387bfd1 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -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) })