Fix collapsed copy mode on resize and with the cursor below the output.

Rebuilding the folded view wrote a linefeed for every source line, including
the blank lines at the end, so shrinking the window scrolled the collapsed
output into history. Stop at the last non-blank line and rebuild a folded view
at the new size when the window is resized.

When no cursor position could be restored, the fallback used the source row,
which can be past the bottom of the shorter folded view and was then used to
index the grid. Fall back to the nearest visible line and clamp to the screen.

Keep the unfolded source only while fold view is on, so plain copy mode is
back to the incremental sync with one copy of the history. Document
toggle-output -m, and rename struct input_osc_133_ctx to struct osc133_marker.
Line numbers started with L stay absolute when fold view is toggled.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Michael Grant
2026-10-08 21:05:05 +02:00
parent 0d65a0f60c
commit b4810e5b2d
6 changed files with 243 additions and 174 deletions

View File

@@ -80,5 +80,28 @@ hidden=$($TMUX display-message -p '#{copy_cursor_line}')
[ "$hidden" != empty-separator ] || exit 1
$TMUX send-keys -X cancel || exit 1
# Shrinking the window must keep the collapsed lines in view.
$TMUX copy-mode -c || exit 1
$TMUX resize-window -y8 || exit 1
sleep 1
resized=$($TMUX capture-pane -Mp)
case "$resized" in
*P0\>*P1\>*) ;;
*) exit 1 ;;
esac
cursor=$($TMUX display-message -p '#{copy_cursor_line}')
[ "$cursor" = 'P1>' ] || exit 1
$TMUX send-keys -X cancel || exit 1
# The cursor must stay on the screen when it is below the folded output.
$TMUX kill-server
$TMUX new-session -d -x80 -y12 "sh -c 'i=0; while [ \$i -lt 3 ]; do printf \"\\033]133;A\\007p\\$ \\033]133;B\\007cmd\\r\\n\\033]133;C\\007one\\r\\ntwo\\r\\nthree\\r\\nfour\\r\\n\\033]133;D;0\\007\"; i=\$((i + 1)); done; printf \"\\033]133;A\\007p\\$ \"; j=0; while [ \$j -lt 8 ]; do printf \"live\\r\\n\"; j=\$((j + 1)); done; exec sleep 100'" || exit 1
sleep 1
$TMUX copy-mode -c || exit 1
cursor=$($TMUX display-message -p '#{copy_cursor_y}')
[ "$cursor" -lt 12 ] || exit 1
$TMUX send-keys -X cancel || exit 1
$TMUX kill-server 2>/dev/null
exit 0