commandline --showing-suggestion to ignore single-space autosuggestion

All-whitespace autocompletions are invisible, no matter the cursor
shape.  We do offer such autosuggestions after typing a command name
such as "fish". Since the autosuggestion is invisible it's probably
not useful. It also does no harm except when using a binding like

	bind ctrl-g '
	    if commandline --showing-suggestion
	        commandline -f accept-autosuggestion
	    else
	        up-or-search
	    end'

where typing "fish<ctrl-g>" surprisingly does not perform a history
search.  Fix this by detecting this specific case. In future we
could probably stop showing autosuggestions whenever they only
contain whitespace.
This commit is contained in:
Johannes Altmanninger 2024-10-30 06:19:04 +01:00
parent ec939fb22f
commit cd3b6f9124

View file

@ -963,7 +963,10 @@ pub fn reader_showing_suggestion(parser: &Parser) -> bool {
}
if let Some(data) = current_data() {
let reader = Reader { parser, data };
!reader.autosuggestion.is_empty()
let suggestion = &reader.autosuggestion.text;
let is_single_space = suggestion.ends_with(L!(" "))
&& reader.command_line.text() == suggestion[..suggestion.len() - 1];
!suggestion.is_empty() && !is_single_space
} else {
false
}