[PR #14661] Correct the cursor invalidation region #30193

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

Original Pull Request: https://github.com/microsoft/terminal/pull/14661

State: closed
Merged: Yes


Depending on the line rendition, and whether the cursor is over a wide
character or not, it's possible for the width to take up anywhere from 1
to 4 cells. And when it's more than 1 cell wide, part of the cursor may
end up off screen. However, our bounds check requires the entire cursor
to be on screen, otherwise it doesn't render anything, and that can
result in cursor droppings being left behind. This PR fixes that.

The bounds check that is causing this issue was introduced in #13001 to
fix a debug assertion.

To fix this, I've removed the bounds checking, and instead clip the
cursor rect to the boundaries of the viewport. This is what the original
code was trying to do prior to the #13001 fix, but was mistakenly using
the Viewport:Clamp method, instead of TrimToViewport. Since this
implementation doesn't require a clamp, there should be no risk of the
debug assertion returning.

Validation Steps Performed

I've confirmed that the test case in #14657 is now working correctly,
and not leaving cursor droppings behind. I've also tested under conhost
with buffer sizes wider than the viewport, and confirmed it can handle a
wide cursor partially scrolled off screen.

Closes #14657

**Original Pull Request:** https://github.com/microsoft/terminal/pull/14661 **State:** closed **Merged:** Yes --- Depending on the line rendition, and whether the cursor is over a wide character or not, it's possible for the width to take up anywhere from 1 to 4 cells. And when it's more than 1 cell wide, part of the cursor may end up off screen. However, our bounds check requires the entire cursor to be on screen, otherwise it doesn't render anything, and that can result in cursor droppings being left behind. This PR fixes that. The bounds check that is causing this issue was introduced in #13001 to fix a debug assertion. To fix this, I've removed the bounds checking, and instead clip the cursor rect to the boundaries of the viewport. This is what the original code was trying to do prior to the #13001 fix, but was mistakenly using the `Viewport:Clamp` method, instead of `TrimToViewport`. Since this implementation doesn't require a clamp, there should be no risk of the debug assertion returning. ## Validation Steps Performed I've confirmed that the test case in #14657 is now working correctly, and not leaving cursor droppings behind. I've also tested under conhost with buffer sizes wider than the viewport, and confirmed it can handle a wide cursor partially scrolled off screen. Closes #14657
claunia added the pull-request label 2026-01-31 09:39:15 +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#30193