[PR #14874] Merge the LineFeed functionality into AdaptDispatch #30301

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

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

State: closed
Merged: Yes


The main purpose of this PR was to merge the ITerminalApi::LineFeed
implementations into a shared method in AdaptDispatch, and avoid the
VT code path depending on the AdjustCursorPosition function (which
could then be massively simplified). This refactoring also fixes some
bugs that existed in the original LineFeed implementations.

References and Relevant Issues

This helps to close the gap between the Conhost and Terminal (#13408).
This improves some of the scrollbar mark bugs mentioned in #11000.

Detailed Description of the Pull Request / Additional comments

I had initially hoped the line feed functionality could be implemented
entirely within AdaptDispatch, but there is still some Conhost and
Terminal-specific behavior that needs to be triggered when we reach the
bottom of the buffer, and the row coordinates are cycled.

In Conhost we need to trigger an accessibility scroll event, and in
Windows Terminal we need to update selection and marker offsets, reset
pattern intervals, and preserve the user's scroll offset. This is now
handled by a new NotifyBufferRotation method in ITerminalApi.

But this made me realise that the _EraseAll method should have been
doing the same thing when it reached the bottom of the buffer. So I've
added a call to the new NotifyBufferRotation API from there as well.

And in the case of Windows Terminal, the scroll offset preservation was
something that was also needed for a regular viewport pan. So I've put
that in a separate _PreserveUserScrollOffset method which is called
from the SetViewportPosition handler as well.

Validation Steps Performed

Because of the API changes, there were a number of unit tests that
needed to be updated:

  • Some of the ScreenBufferTests were accessing margin state in the
    SCREEN_INFORMATION class which doesn't exist anymore, so I had to add
    a little helper function which now manually detects the active margins.

  • Some of the AdapterTest tests were dependent on APIs that no longer
    exist, so they needed to be rewritten so they now check the resulting
    state rather than expecting a mock API call.

  • The ScrollWithMargins test in ConptyRoundtripTests was testing
    functionality that didn't previously work correctly (issue #3673). Now
    that it's been fixed, that test needed to be updated accordingly.

Other than getting the unit tests working, I've manually verified that
issue #3673 is now fixed. And I've also checked that the scroll markers,
selections, and user scroll offset are all being updated correctly, both
with a regular viewport pan, as well as when overrunning the buffer.

Closes #3673

**Original Pull Request:** https://github.com/microsoft/terminal/pull/14874 **State:** closed **Merged:** Yes --- The main purpose of this PR was to merge the `ITerminalApi::LineFeed` implementations into a shared method in `AdaptDispatch`, and avoid the VT code path depending on the `AdjustCursorPosition` function (which could then be massively simplified). This refactoring also fixes some bugs that existed in the original `LineFeed` implementations. ## References and Relevant Issues This helps to close the gap between the Conhost and Terminal (#13408). This improves some of the scrollbar mark bugs mentioned in #11000. ## Detailed Description of the Pull Request / Additional comments I had initially hoped the line feed functionality could be implemented entirely within `AdaptDispatch`, but there is still some Conhost and Terminal-specific behavior that needs to be triggered when we reach the bottom of the buffer, and the row coordinates are cycled. In Conhost we need to trigger an accessibility scroll event, and in Windows Terminal we need to update selection and marker offsets, reset pattern intervals, and preserve the user's scroll offset. This is now handled by a new `NotifyBufferRotation` method in `ITerminalApi`. But this made me realise that the `_EraseAll` method should have been doing the same thing when it reached the bottom of the buffer. So I've added a call to the new `NotifyBufferRotation` API from there as well. And in the case of Windows Terminal, the scroll offset preservation was something that was also needed for a regular viewport pan. So I've put that in a separate `_PreserveUserScrollOffset` method which is called from the `SetViewportPosition` handler as well. ## Validation Steps Performed Because of the API changes, there were a number of unit tests that needed to be updated: - Some of the `ScreenBufferTests` were accessing margin state in the `SCREEN_INFORMATION` class which doesn't exist anymore, so I had to add a little helper function which now manually detects the active margins. - Some of the `AdapterTest` tests were dependent on APIs that no longer exist, so they needed to be rewritten so they now check the resulting state rather than expecting a mock API call. - The `ScrollWithMargins` test in `ConptyRoundtripTests` was testing functionality that didn't previously work correctly (issue #3673). Now that it's been fixed, that test needed to be updated accordingly. Other than getting the unit tests working, I've manually verified that issue #3673 is now fixed. And I've also checked that the scroll markers, selections, and user scroll offset are all being updated correctly, both with a regular viewport pan, as well as when overrunning the buffer. Closes #3673
claunia added the pull-request label 2026-01-31 09:39:55 +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#30301