[PR #8434] Retain horizontal viewport offset when moving to bottom #27196

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

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

State: closed
Merged: Yes


When the viewport is moved to the "virtual bottom" of the buffer (via
the MoveToBottom method), it is important that the horizontal viewport
offset be left as it is, otherwise that can result in some undesirable
side effects.

Since the VT coordinate system is relative to the top of the viewport,
many VT operations call the MoveToBottom method to make sure the
viewport is correctly positioned before proceeding. There is no need for
the horizontal position to be adjusted, though, since the X coordinates
are not constrained by the viewport, but are instead relative to the
underlying buffer.

Setting the viewport X coordinate to 0 in MoveToBottom (as we were
previously doing) could result in the cursor being pushed off screen.
And if the operation itself was moving the cursor, that would then
trigger another viewport move to bring the cursor back into view. These
conflicting movements meant the viewport was always forced as far left
as possible, and could also result in cursor "droppings" as the cursor
lost track of where it had been.

I've now fixed this by updating the GetVirtualViewport method to match
the horizontal offset of the active viewport, instead of having the X
coordinate hardcoded to 0.

Validation Steps Performed

I've manually confirmed that this fixes the cursor "droppings" test case
reported in issue #8213.

I've also added a screen buffer test that makes sure the MoveToBottom
method is working as expected, and not changing the horizontal viewport
offset when it moves down.

Closes #8213

**Original Pull Request:** https://github.com/microsoft/terminal/pull/8434 **State:** closed **Merged:** Yes --- When the viewport is moved to the "virtual bottom" of the buffer (via the `MoveToBottom` method), it is important that the horizontal viewport offset be left as it is, otherwise that can result in some undesirable side effects. Since the VT coordinate system is relative to the top of the viewport, many VT operations call the `MoveToBottom` method to make sure the viewport is correctly positioned before proceeding. There is no need for the horizontal position to be adjusted, though, since the X coordinates are not constrained by the viewport, but are instead relative to the underlying buffer. Setting the viewport X coordinate to 0 in `MoveToBottom` (as we were previously doing) could result in the cursor being pushed off screen. And if the operation itself was moving the cursor, that would then trigger another viewport move to bring the cursor back into view. These conflicting movements meant the viewport was always forced as far left as possible, and could also result in cursor "droppings" as the cursor lost track of where it had been. I've now fixed this by updating the `GetVirtualViewport` method to match the horizontal offset of the active viewport, instead of having the X coordinate hardcoded to 0. ## Validation Steps Performed I've manually confirmed that this fixes the cursor "droppings" test case reported in issue #8213. I've also added a screen buffer test that makes sure the `MoveToBottom` method is working as expected, and not changing the horizontal viewport offset when it moves down. Closes #8213
claunia added the pull-request label 2026-01-31 09:20:35 +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#27196