on master help sign in
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.

commit140df92d7936e1fd036128d98ab565d92e9d2bd8 authorMichael Davis <mcarsondavis@gmail.com> dateThu 3 Nov 2022, 21:02 (4 years ago) parent3d283b2
1 file changed+4−1
helix-term/src/commands/typed.rs+4−1
helix-term/src/commands/typed.rs+4−1
@@ -2216,12 +2216,15 @@ pub(super) fn command_mode(cx: &mut Context) {
22162216 ..
22172217 }) = typed::TYPABLE_COMMAND_MAP.get(&parts[0] as &str)
22182218 {
2219+ let part_len = shellwords::escape(part.clone()).len();
2220+
22192221 completer(editor, part)
22202222 .into_iter()
22212223 .map(|(range, file)| {
22222224 let file = shellwords::escape(file);
2225+
22232226 // offset ranges to input
2224− let offset = input.len() - part.len();
2227+ let offset = input.len() - part_len;
22252228 let range = (range.start + offset)..;
22262229 (range, file)
22272230 })