From 2cccb3f09c52824bf070e127c0b196ed8d8e7555 Mon Sep 17 00:00:00 2001
From: Ivan Gulakov <44394533+ogimgd@users.noreply.github.com>
Date: Thu, 18 May 2023 08:27:29 +0200
Subject: [PATCH] Fix completion on paths containing spaces (#6779)

There was an issue with autocompletion of a path with a space in it.

Before:

:o test\ dir -> <TAB> -> test\ dirfile1

After:

:o test\ dir -> <TAB> -> test\ dir\file1
---
 helix-term/src/commands/typed.rs | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs
index 16ee83d7..81a24059 100644
--- a/helix-term/src/commands/typed.rs
+++ b/helix-term/src/commands/typed.rs
@@ -2847,13 +2847,10 @@ pub(super) fn command_mode(cx: &mut Context) {
             } else {
                 // Otherwise, use the command's completer and the last shellword
                 // as completion input.
-                let (part, part_len) = if words.len() == 1 || shellwords.ends_with_whitespace() {
+                let (word, word_len) = if words.len() == 1 || shellwords.ends_with_whitespace() {
                     (&Cow::Borrowed(""), 0)
                 } else {
-                    (
-                        words.last().unwrap(),
-                        shellwords.parts().last().unwrap().len(),
-                    )
+                    (words.last().unwrap(), words.last().unwrap().len())
                 };
 
                 let argument_number = argument_number_of(&shellwords);
@@ -2862,13 +2859,13 @@ pub(super) fn command_mode(cx: &mut Context) {
                     .get(&words[0] as &str)
                     .map(|tc| tc.completer_for_argument_number(argument_number))
                 {
-                    completer(editor, part)
+                    completer(editor, word)
                         .into_iter()
                         .map(|(range, file)| {
                             let file = shellwords::escape(file);
 
                             // offset ranges to input
-                            let offset = input.len() - part_len;
+                            let offset = input.len() - word_len;
                             let range = (range.start + offset)..;
                             (range, file)
                         })