@@ -123,6 +123,7 @@ class ScreenBufferTests
123123 TEST_METHOD (VtResizePreservingAttributes);
124124
125125 TEST_METHOD (VtSoftResetCursorPosition);
126+ TEST_METHOD (VtSoftResetAltBufferCursorState);
126127
127128 TEST_METHOD (VtScrollMarginsNewlineColor);
128129
@@ -1510,6 +1511,30 @@ void ScreenBufferTests::VtSoftResetCursorPosition()
15101511 VERIFY_ARE_EQUAL (til::point (1 , 1 ), cursor.GetPosition ());
15111512}
15121513
1514+ void ScreenBufferTests::VtSoftResetAltBufferCursorState ()
1515+ {
1516+ auto & gci = ServiceLocator::LocateGlobals ().getConsoleInformation ();
1517+ gci.LockConsole (); // Lock must be taken to manipulate buffer.
1518+ auto unlock = wil::scope_exit ([&] { gci.UnlockConsole (); });
1519+
1520+ auto & si = gci.GetActiveOutputBuffer ();
1521+ auto & stateMachine = si.GetStateMachine ();
1522+
1523+ Log::Comment (L" Move cursor on the main buffer." );
1524+ stateMachine.ProcessString (L" \x1b [4;7H" );
1525+ VERIFY_ARE_EQUAL (til::point (6 , 3 ), si.GetTextBuffer ().GetCursor ().GetPosition ());
1526+
1527+ Log::Comment (L" Enter alt buffer, soft reset, and return to main buffer." );
1528+ stateMachine.ProcessString (L" \x1b [?1049h" );
1529+ VERIFY_IS_TRUE (gci.GetActiveOutputBuffer ()._IsAltBuffer ());
1530+ stateMachine.ProcessString (L" \x1b [!p" );
1531+ stateMachine.ProcessString (L" \x1b [?1049l" );
1532+ VERIFY_IS_FALSE (gci.GetActiveOutputBuffer ()._IsAltBuffer ());
1533+
1534+ Log::Comment (L" Returning from alt buffer should restore the main cursor position." );
1535+ VERIFY_ARE_EQUAL (til::point (6 , 3 ), gci.GetActiveOutputBuffer ().GetTextBuffer ().GetCursor ().GetPosition ());
1536+ }
1537+
15131538void ScreenBufferTests::VtScrollMarginsNewlineColor ()
15141539{
15151540 auto & gci = ServiceLocator::LocateGlobals ().getConsoleInformation ();
0 commit comments