From 2ec432838050db3b55e7d5fa9ec85ec5f70dc871 Mon Sep 17 00:00:00 2001 From: Michael Grant Date: Mon, 14 Sep 2026 03:09:42 +0100 Subject: [PATCH] Fixed clear erasinng the usable C marker, use beginning of buffer in this case, up to D marker. --- regress/output-commands.sh | 8 ++++++++ window-copy.c | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/regress/output-commands.sh b/regress/output-commands.sh index bf28be977..11f0fc6fb 100644 --- a/regress/output-commands.sh +++ b/regress/output-commands.sh @@ -139,6 +139,14 @@ $TMUX send-keys -t :below.0 -X copy-selection || exit 1 [ "$($TMUX show-buffer)" = "$(printf 'PID TTY\\n1 pts/0')" ] || exit 1 $TMUX send-keys -t :below.0 -X cancel || exit 1 +$TMUX new-window -d -n clear "printf 'old1\\nold2\\nold3\\nold4\\nold5\\nold6\\n\\033]133;A\\007p\\$ \\033]133;B\\007echo 1; clear; ps\\n\\033]133;C\\0071\\n\\033[H\\033[2JPID TTY\\n1 pts/0\\n\\033]133;D;0\\007separator\\n\\033]133;A\\007p\\$ \\033]133;B\\007'; exec sleep 100" || exit 1 +sleep 1 +$TMUX copy-mode -t :clear || exit 1 +$TMUX send-keys -t :clear.0 C-o || exit 1 +$TMUX send-keys -t :clear.0 -X copy-selection || exit 1 +[ "$($TMUX show-buffer)" = "$(printf 'PID TTY\\n1 pts/0')" ] || exit 1 +$TMUX send-keys -t :clear.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 diff --git a/window-copy.c b/window-copy.c index 4c1a7d8ab..3357765f3 100644 --- a/window-copy.c +++ b/window-copy.c @@ -4211,7 +4211,7 @@ window_copy_find_previous_output_range(struct screen *s, u_int cursor_x, void *buf; u_int start_x, start_y, end_x, end_y, y, total; size_t len; - int found = 0, pending = 0; + int found = 0, have_prompt = 0, pending = 0; total = gd->hsize + gd->sy; for (y = 0; y < total && y <= cursor_y; y++) { @@ -4222,6 +4222,14 @@ window_copy_find_previous_output_range(struct screen *s, u_int cursor_x, start_y = y; pending = 1; } + /* The output may have cleared its C marker from the screen. */ + if (!pending && !have_prompt && + gl->flags & GRID_LINE_END_OUTPUT && + (~gl->flags & GRID_LINE_START_PROMPT || + gl->osc133_data.out_end_col <= gl->osc133_data.prompt_col)) { + start_x = start_y = 0; + pending = 1; + } if (pending && gl->flags & GRID_LINE_END_OUTPUT && (y != cursor_y || gl->osc133_data.out_end_col <= cursor_x)) { end_x = gl->osc133_data.out_end_col; @@ -4238,8 +4246,10 @@ window_copy_find_previous_output_range(struct screen *s, u_int cursor_x, } pending = 0; } - if (gl->flags & GRID_LINE_START_PROMPT) + if (gl->flags & GRID_LINE_START_PROMPT) { pending = 0; + have_prompt = 1; + } } return (found); }