[PR #4403] [MERGED] Move cursor in conpty correctly after a backspace when we've delayed an EOL wrap #25742

Open
opened 2026-01-31 09:11:31 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/4403
Author: @zadjii-msft
Created: 1/29/2020
Status: Merged
Merged: 2/11/2020
Merged by: @undefined

Base: masterHead: dev/migrie/b/1245-I-actually-did-it-this-time


📝 Commits (9)

  • 7fd5d51 This actually fixes this bug - different terminals EOL wrap differently, esp conhost v wt v gnome-terminal. Remove ambiguity - just hardcore move the cursor in this scenario.
  • 9b6554b Add some comments for PR
  • 0a98cce Try adding a test, but I can't get the test to repro the original behavior quite right
  • 40b4966 Revert "Try adding a test, but I can't get the test to repro the original behavior quite right"
  • e0d251c Merge remote-tracking branch 'origin/master' into dev/migrie/b/1245-I-actually-did-it-this-time
  • 774b23b add a test for this particular case
  • 6fcc52c update comments
  • 8a4a40f Merge remote-tracking branch 'origin/master' into dev/migrie/b/1245-I-actually-did-it-this-time
  • 99efb5e Merge remote-tracking branch 'origin/master' into dev/migrie/b/1245-I-actually-did-it-this-time

📊 Changes

4 files changed (+101 additions, -2 deletions)

View changed files

📝 src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp (+68 -0)
📝 src/renderer/vt/XtermEngine.cpp (+15 -0)
📝 src/renderer/vt/paint.cpp (+16 -2)
📝 src/renderer/vt/vtrenderer.hpp (+2 -0)

📄 Description

Summary of the Pull Request

This is a fix that technically was caused by #357, though we didn't have the Terminal at the time, so I only fixed conhost then. When a client app prints the very last column in the buffer, the cursor is often not actually moved to the next row quite yet. The cursor usually just "floats" on the last character of the row, until something happens. This could be a printable character, which will print it on the next line, or a newline, which will move the cursor to the next line manually, or it could be a backspace, which might take the cursor back a character.

Conhost and gnome-terminal behave slightly differently here, and wt behaves differently all together. Heck, conhost behaves differently depending on what output mode you're in.

The scenario in question is typing a full row of text, then hitting backspace to erase the last char of the row.

What we were emitting before in this case was definitely wrong - we'd emit a space at that last row, but then not increment our internal tracker of where the cursor is, so the cursor in conpty and the terminal would be misaligned. The easy fix for this is to make sure to always update the _lastText member appropriately. This is the RightExclusive change.

The second part of this change is to not be so tricksy immediately following a "delayed eol wrap". When we have just printed the last char like that, always use the VT sequence CUP the next time the cursor moves. Depending on the terminal emulator and it's flags, performing a BS in this state might not bring the cursor to the correct position.

References

#405, #780, #357

PR Checklist

Detailed Description of the Pull Request / Additional comments

With the impending #405 PR I have, this still works, but the sequences that are emitted change, so I didn't write a test for this currently.

Validation Steps Performed

Tried the scenario for both #357 and #1245 in inception, gnome-temrinal and wt all, and they all display the cursor correctly.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/4403 **Author:** [@zadjii-msft](https://github.com/zadjii-msft) **Created:** 1/29/2020 **Status:** ✅ Merged **Merged:** 2/11/2020 **Merged by:** [@undefined](undefined) **Base:** `master` ← **Head:** `dev/migrie/b/1245-I-actually-did-it-this-time` --- ### 📝 Commits (9) - [`7fd5d51`](https://github.com/microsoft/terminal/commit/7fd5d515b28dfb857732ac2faa65bdd41dd8e026) This actually fixes this bug - different terminals EOL wrap differently, esp conhost v wt v gnome-terminal. Remove ambiguity - just hardcore move the cursor in this scenario. - [`9b6554b`](https://github.com/microsoft/terminal/commit/9b6554b10f3f6f679c90097547bd72ad0e06ffb7) Add some comments for PR - [`0a98cce`](https://github.com/microsoft/terminal/commit/0a98cceddb79d2b41dd1e45473e30f3a48c7330c) Try adding a test, but I can't get the test to repro the original behavior quite right - [`40b4966`](https://github.com/microsoft/terminal/commit/40b4966782d78ab89b0f40f772c16765fe84b0ef) Revert "Try adding a test, but I can't get the test to repro the original behavior quite right" - [`e0d251c`](https://github.com/microsoft/terminal/commit/e0d251c349f2b3901ae98b67c39d8113fc348eaa) Merge remote-tracking branch 'origin/master' into dev/migrie/b/1245-I-actually-did-it-this-time - [`774b23b`](https://github.com/microsoft/terminal/commit/774b23b2cfd8662d09c54850e46cdbdf1c8a4b7f) add a test for this particular case - [`6fcc52c`](https://github.com/microsoft/terminal/commit/6fcc52cc3b5d9e16ceb42b518ae17fad3f4f704a) update comments - [`8a4a40f`](https://github.com/microsoft/terminal/commit/8a4a40f32ae0d4f15f4f39c82c130ac2d517533d) Merge remote-tracking branch 'origin/master' into dev/migrie/b/1245-I-actually-did-it-this-time - [`99efb5e`](https://github.com/microsoft/terminal/commit/99efb5e7e809c4d00e0e780c9322452fa15f7813) Merge remote-tracking branch 'origin/master' into dev/migrie/b/1245-I-actually-did-it-this-time ### 📊 Changes **4 files changed** (+101 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp` (+68 -0) 📝 `src/renderer/vt/XtermEngine.cpp` (+15 -0) 📝 `src/renderer/vt/paint.cpp` (+16 -2) 📝 `src/renderer/vt/vtrenderer.hpp` (+2 -0) </details> ### 📄 Description ## Summary of the Pull Request This is a fix that technically was caused by #357, though we didn't have the Terminal at the time, so I only fixed conhost then. When a client app prints the very last column in the buffer, the cursor is often not _actually_ moved to the next row quite yet. The cursor usually just "floats" on the last character of the row, until something happens. This could be a printable character, which will print it on the next line, or a newline, which will move the cursor to the next line manually, or it could be a backspace, which might take the cursor back a character. Conhost and gnome-terminal behave slightly differently here, and wt behaves differently all together. Heck, conhost behaves differently depending on what output mode you're in. The scenario in question is typing a full row of text, then hitting backspace to erase the last char of the row. What we were emitting before in this case was definitely wrong - we'd emit a space at that last row, but then not increment our internal tracker of where the cursor is, so the cursor in conpty and the terminal would be misaligned. The easy fix for this is to make sure to always update the `_lastText` member appropriately. This is the `RightExclusive` change. The second part of this change is to not be so tricksy immediately following a "delayed eol wrap". When we have just printed the last char like that, always use the VT sequence CUP the next time the cursor moves. Depending on the terminal emulator and it's flags, performing a BS in this state might not bring the cursor to the correct position. ## References #405, #780, #357 ## PR Checklist * [x] Closes #1245 * [x] I work here * [ ] Tests added/passed * [n/a] Requires documentation to be updated ## Detailed Description of the Pull Request / Additional comments With the impending #405 PR I have, this still works, but the sequences that are emitted change, so I didn't write a test for this currently. ## Validation Steps Performed Tried the scenario for both #357 and #1245 in inception, `gnome-temrinal` and `wt` all, and they all display the cursor correctly. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:11:31 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#25742