From 8c0ac1fe05aa268783d49b4e5ddceee216378369 Mon Sep 17 00:00:00 2001 From: Michael Grant Date: Wed, 9 Sep 2026 06:01:10 +0100 Subject: [PATCH] Fixed output may end on the next prompt's line. --- regress/output-commands.sh | 9 +++++++++ window-copy.c | 15 ++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/regress/output-commands.sh b/regress/output-commands.sh index e7e1bca0e..41b97a983 100644 --- a/regress/output-commands.sh +++ b/regress/output-commands.sh @@ -111,6 +111,15 @@ $TMUX send-keys -t :prompt.0 -X copy-output || exit 1 [ "$($TMUX show-buffer)" = one ] || exit 1 $TMUX send-keys -t :prompt.0 -X cancel || exit 1 +$TMUX new-window -d -n same "printf '\\033]133;A\\007p\\$ \\033]133;B\\007echo\\n\\033]133;C\\007one\\033]133;D;0\\007\\033]133;A\\007p\\$ \\033]133;B\\007'; exec sleep 100" || exit 1 +sleep 1 +$TMUX copy-mode -U -t :same || exit 1 +$TMUX send-keys -t :same.0 -X search-backward one || exit 1 +$TMUX send-keys -t :same.0 -X select-output || exit 1 +$TMUX send-keys -t :same.0 -X copy-selection || exit 1 +[ "$($TMUX show-buffer)" = one ] || exit 1 +$TMUX send-keys -t :same.0 -X cancel || exit 1 + $TMUX copy-mode -t :plain || exit 1 $TMUX send-keys -t :plain.0 -X copy-output -a || exit 1 all=$($TMUX show-buffer) diff --git a/window-copy.c b/window-copy.c index 66b9702ce..8e46845d6 100644 --- a/window-copy.c +++ b/window-copy.c @@ -4165,6 +4165,14 @@ window_copy_find_output_range(struct window_mode_entry *wme, u_int *sx, for (y = prompt_y; y < total; y++) { gl = grid_get_line(gd, y); + /* An output may end on the next prompt's line. */ + if (found_start && gl->flags & GRID_LINE_END_OUTPUT && + (y != prompt_y || gl->osc133_data.out_end_col >= prompt_x)) { + *ex = gl->osc133_data.out_end_col; + *ey = y; + found_end = 1; + break; + } if (y != prompt_y && gl->flags & GRID_LINE_START_PROMPT) break; if (gl->flags & GRID_LINE_START_OUTPUT && @@ -4173,13 +4181,6 @@ window_copy_find_output_range(struct window_mode_entry *wme, u_int *sx, *sy = y; found_start = 1; } - if (found_start && gl->flags & GRID_LINE_END_OUTPUT && - (y != prompt_y || gl->osc133_data.out_end_col >= prompt_x)) { - *ex = gl->osc133_data.out_end_col; - *ey = y; - found_end = 1; - break; - } } if (!found_start) { /* At the live prompt, use the most recent command output. */