From 806734cc568e18def51eb7cb2fd8a9e42524bde0 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 --- CHANGELOG.rst | 2 ++ 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 +++++---- 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7a059d429..06fbda85d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,6 +12,8 @@ Changes since 4.0b1 - Remove the completions for ``dust`` because it conflicted with the Debian/Ubuntu package (:issue:`10922`). - Improve the documentation style for narrow interfaces (like phones) (:issue:`10942`). - Add debug information back to cmake builds with the "RelWithDebInfo" profile (:issue:`10959`). +- the :kbd:`ctrl-c` binding now calls a new bind function called "clear-commandline", + the old behavior that leaves a "^C" marker is available as "cancel-commandline" (:issue:`10935`) fish 4.0b1 (released December 17, 2024) diff --git a/doc_src/cmds/bind.rst b/doc_src/cmds/bind.rst index e62a27fff..ceb4972c7 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. if the terminal doesn't support clearing the screen it is the same as ``repaint``. diff --git a/share/functions/__fish_shared_key_bindings.fish b/share/functions/__fish_shared_key_bindings.fish index 21febbeba..26be8e392 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 clear-screen - 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 fdca0f863..537074677 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 1618d62b3..abea88e6d 100644 --- a/src/input_common.rs +++ b/src/input_common.rs @@ -122,8 +122,8 @@ pub enum ReadlineCmd { ExpandAbbr, DeleteOrExit, Exit, + ClearCommandline, CancelCommandline, - CancelCommandlineTraditional, Cancel, Undo, Redo, diff --git a/src/reader.rs b/src/reader.rs index fe118ae6b..013115898 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -2309,7 +2309,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())); @@ -2319,10 +2319,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) { @@ -2346,7 +2347,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()); } @@ -5042,7 +5043,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. {