From 947883c842256ccab48772ed001f0c0e46d5df8e Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Sun, 10 Mar 2024 09:25:48 +0100 Subject: [PATCH] commandline: Fix setting cursor Fixes #10358 --- src/builtins/commandline.rs | 5 +++-- tests/checks/commandline.fish | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/builtins/commandline.rs b/src/builtins/commandline.rs index 9be604909..dc5397122 100644 --- a/src/builtins/commandline.rs +++ b/src/builtins/commandline.rs @@ -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)); diff --git a/tests/checks/commandline.fish b/tests/checks/commandline.fish index c26374f12..6562d5873 100644 --- a/tests/checks/commandline.fish +++ b/tests/checks/commandline.fish @@ -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