commandline: Fix setting cursor

Fixes #10358
This commit is contained in:
Fabian Boehm 2024-03-10 09:25:48 +01:00
parent 7c173c4b45
commit 947883c842
2 changed files with 7 additions and 2 deletions

View File

@ -517,7 +517,7 @@ pub fn commandline(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr])
if cursor_mode {
if positional_args != 0 {
let arg = w.argv[w.woptind];
let new_pos = match fish_wcstol(&arg[range.start..]) {
let new_pos = match fish_wcstol(arg) {
Err(_) => {
streams
.err
@ -528,7 +528,8 @@ 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, current_buffer.len());
let new_pos =
std::cmp::min(new_pos.max(0) as usize + range.start, 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

@ -21,3 +21,7 @@ or echo Invalid $status
commandline --help &>/dev/null
echo Help $status
# CHECK: Help 0
commandline -pC 0 --input "test | test"
echo $status
# CHECK: 0