diff --git a/src/builtins/commandline.rs b/src/builtins/commandline.rs index 5c6c007ac..580cd1431 100644 --- a/src/builtins/commandline.rs +++ b/src/builtins/commandline.rs @@ -484,7 +484,7 @@ pub fn commandline(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) rstate.cursor_pos + 1 - parse_util_get_offset_from_line( &rstate.text, - i32::try_from(parse_util_lineno(&rstate.text, rstate.cursor_pos)) + i32::try_from(parse_util_lineno(&rstate.text, rstate.cursor_pos) - 1) .unwrap(), ) .unwrap_or_default() diff --git a/tests/checks/tmux-commandline.fish b/tests/checks/tmux-commandline.fish index 99bab16f5..cedf44302 100644 --- a/tests/checks/tmux-commandline.fish +++ b/tests/checks/tmux-commandline.fish @@ -86,3 +86,20 @@ tmux-sleep # CHECK: cursor is at offset 3 in token # CHECK: prompt {{\d+}}> echo foobar isolated-tmux capture-pane -p + +isolated-tmux send-keys C-a C-k \ + 'bind ctrl-x,a "__fish_echo echo line=(commandline --line) column=(commandline --column)"' \ + Enter \ + C-l "echo '1" Enter 2 +tmux-sleep +isolated-tmux send-keys C-x a C-a Up C-x a +tmux-sleep +# CHECK: prompt {{\d+}}> echo '1 +# CHECK: 2 +# CHECK: line=2 column=2 +# CHECK: prompt {{\d+}}> echo '1 +# CHECK: 2 +# CHECK: line=1 column=1 +# CHECK: prompt {{\d+}}> echo '1 +# CHECK: 2 +isolated-tmux capture-pane -p