Fix commandline -C regression handling negative offsets

This commit is contained in:
Johannes Altmanninger 2024-03-10 09:40:44 +01:00
parent 947883c842
commit 94477f3029
2 changed files with 16 additions and 2 deletions

View File

@ -528,8 +528,12 @@ pub fn commandline(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr])
Ok(num) => num,
};
let new_pos =
std::cmp::min(new_pos.max(0) as usize + range.start, current_buffer.len());
let new_pos = std::cmp::min(
range
.start
.saturating_add_signed(isize::try_from(new_pos).unwrap()),
current_buffer.len(),
);
commandline_set_buffer(current_buffer.to_owned(), Some(new_pos));
} else {
streams.out.append(sprintf!("%lu\n", current_cursor_pos));

View File

@ -0,0 +1,10 @@
#RUN: %fish %s
#REQUIRES: command -v tmux
isolated-tmux-start
isolated-tmux send-keys 'bind \eg "commandline -p -C -- -4"' Enter C-l
isolated-tmux send-keys 'echo bar|cat' \eg foo
tmux-sleep
isolated-tmux capture-pane -p
# CHECK: prompt 1> echo foobar|cat