From 19502ff9e7f4fad2f2ce51b0a0e391ee398084e8 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Tue, 11 Mar 2025 19:34:56 +0100 Subject: [PATCH] Add hack to fix off-by-one error in Vi-mode cancel-commandline The new cursor-end-mode "inclusive" (which is active in Vi mode) is causing many issues. One of them is because cancel-commandline wants to move to the end of the command line before printing "^C". Since "inclusive" cursor mode prevents the cursor from moving past the last character, that one will be overwritten with a "^". Hack around this. Closes #11261 (cherry picked from commit b08ff332913c0c23eb59495792d361a65e0f33ef) --- src/reader.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/reader.rs b/src/reader.rs index 64c00d89d..b8149c3b7 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -2347,7 +2347,12 @@ fn handle_readline_command(&mut self, c: ReadlineCmd) { 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)); + { + let tmp = + std::mem::replace(&mut self.cursor_end_mode, CursorEndMode::Exclusive); + self.update_buff_pos(EditableLineTag::Commandline, Some(end)); + self.cursor_end_mode = tmp; + } self.autosuggestion.clear(); // Repaint also changes the actual cursor position