Skip to content

terminal: preserve saved cursor position during repeated widening - #14478

Merged
mitchellh merged 1 commit into
ghostty-org:mainfrom
fornwall:saved-wrap
Sep 30, 2026
Merged

mitchellh merged 1 commit into
ghostty-org:mainfrom
fornwall:saved-wrap

Conversation

@fornwall

Copy link
Copy Markdown
Contributor

Fix saved cursors moving backward during repeated widening. Reflow now accounts for deferred line breaks and pending wrap when clamping tracked positions in trailing blanks.

Starting with a 4-column terminal:

  1. Output abc, then start a new line and output AAA|.
  2. Save the cursor while in pending wrap (ESC 7).
  3. Widen to 5 columns, then to 6 columns.
  4. Restore the cursor (ESC 8) and output X.

Current buggy behaviour:

abc
AAX|

Fixed expected behaviour:

abc
AAA|X

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

Fix saved cursors moving backward during repeated widening. Reflow now accounts for deferred line breaks and pending wrap when clamping tracked positions in trailing blanks.

Starting with a 4-column terminal:

1. Output `abc`, then start a new line and output `AAA|`.
2. Save the cursor while in pending wrap (`ESC 7`).
3. Widen to 5 columns, then to 6 columns.
4. Restore the cursor (`ESC 8`) and output `X`.

Current buggy behaviour:
```
abc
AAX|
```

Fixed expected behaviour:
```
abc
AAA|X
```

Signed-off-by: Fredrik Fornwall <fredrik@fornwall.net>
@fornwall
fornwall requested a review from a team as a code owner September 30, 2026 10:40
@ghostty-bot ghostty-bot Bot added the vt Control sequence related label Sep 30, 2026
@fornwall

Copy link
Copy Markdown
Contributor Author

Used this script to experiment with the issue and the fix: saved-wrap.py

@mitchellh
mitchellh enabled auto-merge September 30, 2026 11:05
@mitchellh
mitchellh merged commit dc3f73a into ghostty-org:main Sep 30, 2026
104 checks passed
@github-actions github-actions Bot added this to the 1.4.0 milestone Sep 30, 2026
@fornwall
fornwall deleted the saved-wrap branch September 30, 2026 12:01
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