Make Ctrl-d behaviour match other tools (#1040)

With this change Ctrl-d behaves differently depending on whether there
is any input text available. If there is, it will delete the character
to the right of the cursor if there is any. If there isn't it will
instead quit interactive mode and leave the original shell command line
unchanged.
This matches other line-based tools like bash and fzf.
This commit is contained in:
Jan Larres 2023-06-12 08:48:32 +12:00 committed by GitHub
parent a224a8e4d3
commit dccdb2c33f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -105,7 +105,7 @@ impl State {
// reset the state, will be set to true later if user really did change it
self.switched_search_mode = false;
match input.code {
KeyCode::Char('c' | 'd' | 'g') if ctrl => return Some(RETURN_ORIGINAL),
KeyCode::Char('c' | 'g') if ctrl => return Some(RETURN_ORIGINAL),
KeyCode::Esc => {
return Some(match settings.exit_mode {
ExitMode::ReturnOriginal => RETURN_ORIGINAL,
@ -165,6 +165,12 @@ impl State {
KeyCode::Delete => {
self.search.input.remove();
}
KeyCode::Char('d') if ctrl => {
if self.search.input.as_str().is_empty() {
return Some(RETURN_ORIGINAL);
}
self.search.input.remove();
}
KeyCode::Char('w') if ctrl => {
// remove the first batch of whitespace
while matches!(self.search.input.back(), Some(c) if c.is_whitespace()) {}