From 4e37dc29dcf6a22a7c54fa45bdbec04cb3c7bd6c Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 7 Oct 2023 23:09:27 +0200 Subject: [PATCH] Fix autosuggestion dropping too many keyword tokens --- fish-rust/src/complete.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fish-rust/src/complete.rs b/fish-rust/src/complete.rs index 43ab5e3a4..a963af3cb 100644 --- a/fish-rust/src/complete.rs +++ b/fish-rust/src/complete.rs @@ -663,7 +663,11 @@ impl<'ctx> Completer<'ctx> { // Hack: fix autosuggestion by removing prefixing "and"s #6249. if is_autosuggest { - tokens.retain(|token| !parser_keywords_is_subcommand(token.get_source(&cmdline))); + let prefixed_supercommand_count = tokens + .iter() + .take_while(|token| parser_keywords_is_subcommand(token.get_source(&cmdline))) + .count(); + tokens.drain(..prefixed_supercommand_count); } // Consume variable assignments in tokens strictly before the cursor.