@@ -122,7 +122,8 @@ class ScreenBufferTests
122122 TEST_METHOD (VtResizeDECCOLM);
123123 TEST_METHOD (VtResizePreservingAttributes);
124124
125- TEST_METHOD (VtSoftResetCursorPosition);
125+ TEST_METHOD (VtSoftResetCursorPosition);
126+ TEST_METHOD (VtSoftResetAltBufferCursorState);
126127
127128 TEST_METHOD (VtScrollMarginsNewlineColor);
128129
@@ -1458,7 +1459,7 @@ void ScreenBufferTests::VtResizePreservingAttributes()
14581459 VERIFY_ARE_EQUAL (testAttr, si.GetTextBuffer ().GetCurrentAttributes ());
14591460}
14601461
1461- void ScreenBufferTests::VtSoftResetCursorPosition ()
1462+ void ScreenBufferTests::VtSoftResetCursorPosition ()
14621463{
14631464 auto & gci = ServiceLocator::LocateGlobals ().getConsoleInformation ();
14641465 auto & si = gci.GetActiveOutputBuffer ().GetActiveBuffer ();
@@ -1508,7 +1509,31 @@ void ScreenBufferTests::VtSoftResetCursorPosition()
15081509 stateMachine.ProcessString (L" \x1b [5;10r" );
15091510 stateMachine.ProcessString (L" \x1b [2;2H" );
15101511 VERIFY_ARE_EQUAL (til::point (1 , 1 ), cursor.GetPosition ());
1511- }
1512+ }
1513+
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+ }
15121537
15131538void ScreenBufferTests::VtScrollMarginsNewlineColor ()
15141539{
0 commit comments