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 <taolzu@gmail.com>

(cherry picked from commit 69f0d960cf)
This commit is contained in:
Johannes Altmanninger 2024-12-30 00:10:59 +01:00 committed by David Adam
parent 5845a3f7ad
commit e6e647092d
2 changed files with 15 additions and 1 deletions

View file

@ -3207,7 +3207,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

View file

@ -241,6 +241,12 @@ expect_prompt("foo")
# send("hh~~bbve~\r")
# expect_prompt("\r\n.*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")
# Now test that exactly the expected bind modes are defined
sendline("bind --list-modes")
expect_prompt(