Fix repeated alt-buffer entry using the stale main viewport size #20825
<!-- AzurePipelinesStatusComment -->
<samp>
Azure Pipelines:<br>
There may be pipelines that require an authorized user to comment /azp run to run.<br>
</samp>
The unit test is a bit verbose because it asserts on things that aren't relevant to what is being tested, but it's okay.
Thank you for the fix!
/azp run
<samp>
Azure Pipelines:<br>
Successfully started running 1 pipeline(s).<br>
1 pipeline(s) were filtered out due to trigger conditions.<br>
</samp>
@huang-404-q we are unable to merge your submission until you accept the Contributor License Agreement.
// Using the active viewport ensures that re-entering the alt buffer doesn't use the stale main viewport dimensions.
_altBufferSize = _GetMutableViewport().Dimensions();
this comment reads like Claudish, and is unpleasant to the eyes
// Activating the alternate screen buffer a second time must not change its size.
plus the CLA.
/azp run
<samp>
Azure Pipelines:<br>
Successfully started running 1 pipeline(s).<br>
1 pipeline(s) were filtered out due to trigger conditions.<br>
</samp>
Approved these changes.
lhecker
Huang-404-Q
Summary
UseAlternateScreenBuffersized the new alt buffer from_mutableViewport, which still holds the main-buffer size while the alt buffer is active: a resize in alt mode only updates_altBufferSize. A second?1049htherefore rebuilt the alt buffer at the pre-resize size.Use the existing
_GetMutableViewport()helper (added for GH#3493), which returns_altBufferSizewhile in the alt buffer.Fixes #20820.
Validation
Added
TerminalApiTest::RepeatedAltBufferEntryKeepsLiveSize: create 100x30, enter alt, resize to 120x40, re-enter?1049h, assert the buffer is 120x40.I could not build or run the test locally: Visual Studio/MSBuild is not installed on this machine. The change is a one-line use of an existing helper; CI should run
Terminal.Core.Unit.Tests.AI assistance
Tool(s) used: Claude Code
How you used it: the assistant read the code, wrote the fix and the test. A human reviewed the diff and takes responsibility for the change.