From c651a79cb6f98f355c61ba2b0535c4a1090b3344 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 26 Jan 2025 15:48:21 +0100 Subject: [PATCH] Fix regression causing builtin commandline to report wrong relative cursor Regressed in 55fd43d86c (Port reader, 2023-12-22). Fixes #11085 --- src/builtins/commandline.rs | 4 +++- tests/checks/tmux-commandline.fish | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/builtins/commandline.rs b/src/builtins/commandline.rs index f726d4939..5c6c007ac 100644 --- a/src/builtins/commandline.rs +++ b/src/builtins/commandline.rs @@ -643,7 +643,9 @@ pub fn commandline(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) ); commandline_set_buffer(None, Some(new_pos)); } else { - streams.out.append(sprintf!("%lu\n", current_cursor_pos)); + streams + .out + .append(sprintf!("%lu\n", current_cursor_pos - range.start)); } return STATUS_CMD_OK; } diff --git a/tests/checks/tmux-commandline.fish b/tests/checks/tmux-commandline.fish index c28fa760e..18968fb04 100644 --- a/tests/checks/tmux-commandline.fish +++ b/tests/checks/tmux-commandline.fish @@ -9,6 +9,7 @@ set -g isolated_tmux_fish_extra_args -C ' bind ctrl-q "functions --erase fish_right_prompt" "commandline \'\'" clear-screen set -g fish_autosuggestion_enabled 0 bind ctrl-g "__fish_echo commandline --current-job" + bind ctrl-t \'__fish_echo echo cursor is at offset $(commandline --cursor --current-token) in token\' ' isolated-tmux-start @@ -61,3 +62,10 @@ isolated-tmux capture-pane -p # CHECK: another job # CHECK: prompt {{\d+}}> echo | echo; # CHECK: another job + +isolated-tmux send-keys C-q 'echo foobar' Left Left Left C-t +tmux-sleep +# CHECK: prompt {{\d+}}> echo foobar +# CHECK: cursor is at offset 3 in token +# CHECK: prompt {{\d+}}> echo foobar +isolated-tmux capture-pane -p