Skip to content

Commit

Permalink
Fix completion on paths containing spaces (helix-editor#6779)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
p13l13d13 authored and Triton171 committed Jun 18, 2023
1 parent be93637 commit 98777c6
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
})
Expand Down

0 comments on commit 98777c6

Please sign in to comment.