forked from extern/nushell
More bug fixes for completions (#2476)
* Use the cursor position for the span when between locations. This fixes a bug where completing ls <TAB> would result in replacing the entire line. * Revert to the default update implementation. Replacing the length of the elected value was intended to do replacement when one moves inside a quote. The problem is that a long elected suggestion could replace bits of a pipeline that are after the cursor. For example: ls <TAB> | get name | str collect
This commit is contained in:
parent
6b5d96337e
commit
860c2a606d
@ -232,10 +232,10 @@ pub fn completion_location(line: &str, block: &Block, pos: usize) -> Vec<Complet
|
|||||||
// is after some character that would imply we're in the command position.
|
// is after some character that would imply we're in the command position.
|
||||||
let start = prev.span.end();
|
let start = prev.span.end();
|
||||||
if line[start..pos].contains(BEFORE_COMMAND_CHARS) {
|
if line[start..pos].contains(BEFORE_COMMAND_CHARS) {
|
||||||
vec![LocationType::Command.spanned(Span::unknown())]
|
vec![LocationType::Command.spanned(Span::new(pos, pos))]
|
||||||
} else {
|
} else {
|
||||||
// TODO this should be able to be mapped to a command
|
// TODO this should be able to be mapped to a command
|
||||||
vec![LocationType::Argument(command, None).spanned(Span::unknown())]
|
vec![LocationType::Argument(command, None).spanned(Span::new(pos, pos))]
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Cursor is before any possible completion location, so must be a command
|
// Cursor is before any possible completion location, so must be a command
|
||||||
|
@ -54,7 +54,7 @@ impl rustyline::completion::Completer for Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update(&self, line: &mut rustyline::line_buffer::LineBuffer, start: usize, elected: &str) {
|
fn update(&self, line: &mut rustyline::line_buffer::LineBuffer, start: usize, elected: &str) {
|
||||||
let end = (start + elected.len()).min(line.len());
|
let end = line.pos();
|
||||||
line.replace(start..end, elected)
|
line.replace(start..end, elected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user