From 69f0d960cf69e4f390f41a47227389a2aac77237 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Mon, 30 Dec 2024 00:10:59 +0100 Subject: [PATCH] Fix off-by-one error in Vi-style upcase-word at commandline end cursor_selection_mode=inclusive means the commandline position is bounded by the last character. Fix a loop that fails to account for this. Fixes d51f669647 (Vi mode: avoid placing cursor beyond last character, 2024-02-14). This change looks very odd because if the commandline is like echo foo. it makes us try to uppercase the trailing period even though that's not part of word range. Hopefully this is harmless. Note that there seem to be more issues remaining, for example Vi-mode paste leaves the cursor in an out-of-bounds odd position. Fixes #10952 Closes #10953 Reported-by: Lzu Tao --- src/reader.rs | 10 +++++++++- tests/pexpects/bind.py | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/reader.rs b/src/reader.rs index 59f8b8365..5a8653a2d 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -3204,7 +3204,15 @@ impl<'a> Reader<'a> { ); let (elt, el) = self.active_edit_line(); let mut replacement = WString::new(); - while pos < el.position() { + while pos + < if self.cursor_selection_mode == CursorSelectionMode::Inclusive + && self.is_at_end(el) + { + el.len() + } else { + el.position() + } + { let chr = el.text().as_char_slice()[pos]; // We always change the case; this decides whether we go uppercase (true) or diff --git a/tests/pexpects/bind.py b/tests/pexpects/bind.py index d1588464f..991325e33 100644 --- a/tests/pexpects/bind.py +++ b/tests/pexpects/bind.py @@ -241,6 +241,12 @@ expect_prompt("foo") # send("hh~~bbve~\r") # expect_prompt(TO_END + "SOME TeXT\r\n", unmatched="Couldn't find expected output 'SOME TeXT") +send("echo echo") +send("\033") +sleep(0.200) +send("bgU\r") +expect_prompt("echo ECHO") + send("echo 125") send("\033") sleep(0.200)