From 28233b07118df75c2c70463eadad8598480b99ef Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Tue, 14 Jan 2025 19:58:26 +0100 Subject: [PATCH] Make new ctrl-c behavior "clear-commandline" And leave the old behavior under the name "cancel-commandline". This renames "cancel-commandline-traditional" back to "cancel-commandline", so the old name triggers the old behavior. Fixes #10935 --- doc_src/cmds/bind.rst | 3 +++ share/functions/__fish_shared_key_bindings.fish | 2 +- share/functions/fish_vi_key_bindings.fish | 2 +- src/input.rs | 2 +- src/input_common.rs | 2 +- src/reader.rs | 9 +++++---- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/doc_src/cmds/bind.rst b/doc_src/cmds/bind.rst index d8bee0fc8..914a30b61 100644 --- a/doc_src/cmds/bind.rst +++ b/doc_src/cmds/bind.rst @@ -170,6 +170,9 @@ The following special input functions are available: ``capitalize-word`` make the current word begin with a capital letter +``clear-commandline`` + empty the entire commandline + ``clear-screen`` clears the screen and redraws the prompt. diff --git a/share/functions/__fish_shared_key_bindings.fish b/share/functions/__fish_shared_key_bindings.fish index 1cea64246..fdfdbb727 100644 --- a/share/functions/__fish_shared_key_bindings.fish +++ b/share/functions/__fish_shared_key_bindings.fish @@ -67,7 +67,7 @@ function __fish_shared_key_bindings -d "Bindings shared between emacs and vi mod bind --preset $argv alt-o __fish_preview_current_file bind --preset $argv alt-w __fish_whatis_current_token bind --preset $argv ctrl-l scrollback-push repaint - bind --preset $argv ctrl-c cancel-commandline + bind --preset $argv ctrl-c clear-commandline bind --preset $argv ctrl-u backward-kill-line bind --preset $argv ctrl-k kill-line bind --preset $argv ctrl-w backward-kill-path-component diff --git a/share/functions/fish_vi_key_bindings.fish b/share/functions/fish_vi_key_bindings.fish index 0a1ef6a9a..cb8428e17 100644 --- a/share/functions/fish_vi_key_bindings.fish +++ b/share/functions/fish_vi_key_bindings.fish @@ -64,7 +64,7 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' # Default (command) mode bind -s --preset :,q exit - bind -s --preset -m insert ctrl-c cancel-commandline repaint-mode + bind -s --preset -m insert ctrl-c clear-commandline repaint-mode bind -s --preset -M default h backward-char bind -s --preset -M default l forward-char bind -s --preset -m insert enter execute diff --git a/src/input.rs b/src/input.rs index 4e2815539..6c4a61580 100644 --- a/src/input.rs +++ b/src/input.rs @@ -146,8 +146,8 @@ const INPUT_FUNCTION_METADATA: &[InputFunctionMetadata] = &[ make_md(L!("beginning-of-line"), ReadlineCmd::BeginningOfLine), make_md(L!("cancel"), ReadlineCmd::Cancel), make_md(L!("cancel-commandline"), ReadlineCmd::CancelCommandline), - make_md(L!("cancel-commandline-traditional"), ReadlineCmd::CancelCommandlineTraditional), make_md(L!("capitalize-word"), ReadlineCmd::CapitalizeWord), + make_md(L!("clear-commandline"), ReadlineCmd::ClearCommandline), make_md(L!("clear-screen"), ReadlineCmd::ClearScreenAndRepaint), make_md(L!("complete"), ReadlineCmd::Complete), make_md(L!("complete-and-search"), ReadlineCmd::CompleteAndSearch), diff --git a/src/input_common.rs b/src/input_common.rs index c31ec6dca..669c82c55 100644 --- a/src/input_common.rs +++ b/src/input_common.rs @@ -124,8 +124,8 @@ pub enum ReadlineCmd { ExpandAbbr, DeleteOrExit, Exit, + ClearCommandline, CancelCommandline, - CancelCommandlineTraditional, Cancel, Undo, Redo, diff --git a/src/reader.rs b/src/reader.rs index b82622784..2b525f490 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -2552,7 +2552,7 @@ impl<'a> Reader<'a> { self.data .update_buff_pos(EditableLineTag::Commandline, Some(self.command_line_len())); } - rl::CancelCommandline | rl::CancelCommandlineTraditional => { + rl::CancelCommandline | rl::ClearCommandline => { if self.conf.exit_on_interrupt { self.parser .set_last_statuses(Statuses::just(STATUS_CMD_ERROR.unwrap())); @@ -2562,10 +2562,11 @@ impl<'a> Reader<'a> { if self.command_line.is_empty() { return; } - if c == rl::CancelCommandlineTraditional { + if c == rl::CancelCommandline { // Move cursor to the end of the line. let end = self.command_line.len(); self.update_buff_pos(EditableLineTag::Commandline, Some(end)); + self.autosuggestion.clear(); // Repaint also changes the actual cursor position if self.is_repaint_needed(None) { @@ -2589,7 +2590,7 @@ impl<'a> Reader<'a> { EditableLineTag::Commandline, Edit::new(0..self.command_line_len(), L!("").to_owned()), ); - if c == rl::CancelCommandlineTraditional { + if c == rl::CancelCommandline { self.screen .reset_abandoning_line(usize::try_from(termsize_last().width).unwrap()); } @@ -5426,7 +5427,7 @@ fn command_ends_paging(c: ReadlineCmd, focused_on_search_field: bool) -> bool { | rl::AcceptAutosuggestion | rl::DeleteOrExit | rl::CancelCommandline - | rl::CancelCommandlineTraditional + | rl::ClearCommandline | rl::Cancel => // These commands always end paging. {