Skip to content

Commit

Permalink
Capture word parts while calculating shellwords (helix-editor#4632)
Browse files Browse the repository at this point in the history
This fixes an edge case for completing shellwords. With a file
"a b.txt" in the current directory, the sequence `:open a\<tab>`
will result in the prompt containing `:open aa\ b.txt`. This is
because the length of the input which is trimmed when replacing with
completion is calculated on the part of the input which is parsed by
shellwords and then escaped (in a separate operation), which is lossy.
In this case it loses the trailing backslash.

The fix provided here refactors shellwords to track both the _words_
(shellwords with quotes and escapes resolved) and the _parts_ (chunks
of the input which turned into each word, with separating whitespace
removed). When calculating how much of the input to delete when
replacing with the completion item, we now use the length of the last
part.

This also allows us to eliminate the duplicate work done in the
`ends_with_whitespace` check.
  • Loading branch information
the-mikedavis authored and Shekhinah Memmel committed Dec 11, 2022
1 parent 7cff2b6 commit cf08e42
Show file tree
Hide file tree
Showing 2 changed files with 186 additions and 170 deletions.
Loading

0 comments on commit cf08e42

Please sign in to comment.