Fix issue 6596 (#6603)

* Fix issue 6596

* add two unit tests

* fix pipe

* add cp test

* fix test on windows
This commit is contained in:
Kangaxx-0
2022-09-29 01:43:58 -07:00
committed by GitHub
parent 1a3762b905
commit 7b9ad9d2e5
2 changed files with 66 additions and 4 deletions

View File

@ -123,7 +123,8 @@ impl NuCompleter {
let offset = working_set.next_span_start();
let (mut new_line, alias_offset) = try_find_alias(line.as_bytes(), &working_set);
let initial_line = line.to_string();
new_line.push(b'a');
let alias_total_offset: usize = alias_offset.iter().sum();
new_line.insert(alias_total_offset + pos, b'a');
let pos = offset + pos;
let config = self.engine_state.get_config();
@ -169,9 +170,10 @@ impl NuCompleter {
}
};
// Parses the prefix
// Parses the prefix. Completion should look up to the cursor position, not after.
let mut prefix = working_set.get_span_contents(flat.0).to_vec();
prefix.remove(pos - (flat.0.start - span_offset));
let index = pos - (flat.0.start - span_offset);
prefix.drain(index..);
// Variables completion
if prefix.starts_with(b"$") || most_left_var.is_some() {