diff --git a/src/builtins/commandline.rs b/src/builtins/commandline.rs index dc5397122..4afcdf9d0 100644 --- a/src/builtins/commandline.rs +++ b/src/builtins/commandline.rs @@ -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)); diff --git a/tests/checks/tmux-commandline.fish b/tests/checks/tmux-commandline.fish new file mode 100644 index 000000000..533546f92 --- /dev/null +++ b/tests/checks/tmux-commandline.fish @@ -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