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.