From b5d591bb09efd9f3e67c072b6a395080a6abd041 Mon Sep 17 00:00:00 2001 From: Jason Gedge Date: Mon, 31 Aug 2020 22:13:00 -0400 Subject: [PATCH] Improve support for completing within quotes. (#2474) We ensure the partially cimpleted item doesn't include the end quote. We also ensure that the appropriate span is replaced, not just the suggested position up to the cursor position. --- crates/nu-cli/src/shell/completer.rs | 2 +- crates/nu-cli/src/shell/helper.rs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/nu-cli/src/shell/completer.rs b/crates/nu-cli/src/shell/completer.rs index a0c8d6750e..a49a2d3fc8 100644 --- a/crates/nu-cli/src/shell/completer.rs +++ b/crates/nu-cli/src/shell/completer.rs @@ -63,7 +63,7 @@ impl NuCompleter { let partial = if let Some(quote_char) = quote_char { if partial.ends_with(quote_char) { - &partial[..partial.len()] + &partial[..partial.len() - 1] } else { partial } diff --git a/crates/nu-cli/src/shell/helper.rs b/crates/nu-cli/src/shell/helper.rs index 3c67149b1b..b17856a9da 100644 --- a/crates/nu-cli/src/shell/helper.rs +++ b/crates/nu-cli/src/shell/helper.rs @@ -52,6 +52,11 @@ impl rustyline::completion::Completer for Helper { let ctx = completion::Context::new(&self.context); Ok(self.completer.complete(line, pos, &ctx)) } + + fn update(&self, line: &mut rustyline::line_buffer::LineBuffer, start: usize, elected: &str) { + let end = (start + elected.len()).min(line.len()); + line.replace(start..end, elected) + } } impl rustyline::hint::Hinter for Helper {