Skip to content

terminal: fix reverse wrap cursor jump - #14390

Merged
mitchellh merged 1 commit into
ghostty-org:mainfrom
fornwall:reverse-wrapping
Sep 25, 2026
Merged

mitchellh merged 1 commit into
ghostty-org:mainfrom
fornwall:reverse-wrapping

Conversation

@fornwall

Copy link
Copy Markdown
Contributor

With reverse wrapping enabled, a cursor-left (CUB) or Backspace after DECRC could jump the cursor down to the top of the scrolling region.

This happened when the restored cursor had pending wrap set and clearing it consumed the whole move, so the left-margin handling ran with nothing left to move. Stop once pending wrap is cleared and no move remains.

Reproduce:

printf '%b' \
  '\0033[?6;1045l\0033[?7;45;69h\0033[2J' \
  '\0033[1;2sAB\00337\0033[2;5s\0033[3;5r\00338\0033[1DX' \
  '\0033[?45;69l\0033[r\0033[6;1H'

This saves pending wrap, changes the margins, restores the cursor, then moves left and prints X.

  • Before: AB on row 1; X at row 3, column 2.
  • After: AX on row 1.

Tested with Kitty, which handles this correctly.

AI disclaimer: Created with gpt-6 astra using codex. Iterated on, reviewed and manually tested by me.

Stop when clearing pending wrap consumes the last cursor-left step.
Otherwise, margin handling can move a restored cursor down to the top
scrolling margin. Add a regression test that restores pending wrap at
the left margin above the top scrolling margin.

Signed-off-by: Fredrik Fornwall <fredrik@fornwall.net>
@fornwall
fornwall requested a review from a team as a code owner September 25, 2026 06:21
@ghostty-bot ghostty-bot Bot added the vt Control sequence related label Sep 25, 2026
@mitchellh
mitchellh merged commit 2fe073a into ghostty-org:main Sep 25, 2026
99 checks passed
@github-actions github-actions Bot added this to the 1.4.0 milestone Sep 25, 2026
@fornwall
fornwall deleted the reverse-wrapping branch September 26, 2026 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

vt Control sequence related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants