Skip to content

Commit 1fccbc5

Browse files
j4jamesminiksa
authored andcommitted
Move cursor to left margin for IL and DL controls (microsoft#2731)
* Move cursor position to the left margin after execution of the IL and DL escape sequences. * Update IL and DL screen buffer tests to account for the cursor moving to the left margin.
1 parent 537258a commit 1fccbc5

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

src/host/getset.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,6 +2021,7 @@ void DoSrvPrivateSetDefaultTabStops()
20212021

20222022
// Routine Description:
20232023
// - internal logic for adding or removing lines in the active screen buffer
2024+
// this also moves the cursor to the left margin, which is expected behaviour for IL and DL
20242025
// Parameters:
20252026
// - count - the number of lines to modify
20262027
// - insert - true if inserting lines, false if deleting lines
@@ -2069,6 +2070,10 @@ void DoSrvPrivateModifyLinesImpl(const unsigned int count, const bool insert)
20692070
screenInfo.GetAttributes());
20702071
}
20712072
CATCH_LOG();
2073+
2074+
// The IL and DL controls are also expected to move the cursor to the left margin.
2075+
// For now this is just column 0, since we don't yet support DECSLRM.
2076+
LOG_IF_NTSTATUS_FAILED(screenInfo.SetCursorPosition({ 0, cursorPosition.Y }, false));
20722077
}
20732078
}
20742079

src/host/ut_host/ScreenBufferTests.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3230,8 +3230,16 @@ void ScreenBufferTests::ScrollOperations()
32303230
VERIFY_SUCCEEDED(si.SetCursorPosition(cursorPos, true));
32313231
stateMachine.ProcessString(escapeSequence.str());
32323232

3233-
Log::Comment(L"Verify cursor didn't move.");
3234-
VERIFY_ARE_EQUAL(cursorPos, cursor.GetPosition());
3233+
// The cursor shouldn't move.
3234+
auto expectedCursorPos = cursorPos;
3235+
// Unless this is an IL or DL control, which moves the cursor to the left margin.
3236+
if (scrollType == InsertLine || scrollType == DeleteLine)
3237+
{
3238+
expectedCursorPos.X = 0;
3239+
}
3240+
3241+
Log::Comment(L"Verify expected cursor position.");
3242+
VERIFY_ARE_EQUAL(expectedCursorPos, cursor.GetPosition());
32353243

32363244
Log::Comment(L"Field of Zs outside viewport should remain unchanged.");
32373245
VERIFY_IS_TRUE(_ValidateLinesContain(0, viewportStart, bufferChar, bufferAttr));
@@ -3749,7 +3757,8 @@ void ScreenBufferTests::InsertLinesInMargins()
37493757
Log::Comment(NoThrowString().Format(
37503758
L"viewport=%s", VerifyOutputTraits<SMALL_RECT>::ToString(si.GetViewport().ToInclusive()).GetBuffer()));
37513759

3752-
VERIFY_ARE_EQUAL(4, cursor.GetPosition().X);
3760+
// Verify cursor moved to left margin.
3761+
VERIFY_ARE_EQUAL(0, cursor.GetPosition().X);
37533762
VERIFY_ARE_EQUAL(2, cursor.GetPosition().Y);
37543763
{
37553764
auto iter0 = tbi.GetCellDataAt({ 0, 0 });
@@ -3783,7 +3792,8 @@ void ScreenBufferTests::InsertLinesInMargins()
37833792
Log::Comment(NoThrowString().Format(
37843793
L"viewport=%s", VerifyOutputTraits<SMALL_RECT>::ToString(si.GetViewport().ToInclusive()).GetBuffer()));
37853794

3786-
VERIFY_ARE_EQUAL(4, cursor.GetPosition().X);
3795+
// Verify cursor moved to left margin.
3796+
VERIFY_ARE_EQUAL(0, cursor.GetPosition().X);
37873797
VERIFY_ARE_EQUAL(1, cursor.GetPosition().Y);
37883798
{
37893799
auto iter0 = tbi.GetCellDataAt({ 0, 0 });
@@ -3824,7 +3834,8 @@ void ScreenBufferTests::DeleteLinesInMargins()
38243834
Log::Comment(NoThrowString().Format(
38253835
L"viewport=%s", VerifyOutputTraits<SMALL_RECT>::ToString(si.GetViewport().ToInclusive()).GetBuffer()));
38263836

3827-
VERIFY_ARE_EQUAL(4, cursor.GetPosition().X);
3837+
// Verify cursor moved to left margin.
3838+
VERIFY_ARE_EQUAL(0, cursor.GetPosition().X);
38283839
VERIFY_ARE_EQUAL(2, cursor.GetPosition().Y);
38293840
{
38303841
auto iter0 = tbi.GetCellDataAt({ 0, 0 });
@@ -3858,7 +3869,8 @@ void ScreenBufferTests::DeleteLinesInMargins()
38583869
Log::Comment(NoThrowString().Format(
38593870
L"viewport=%s", VerifyOutputTraits<SMALL_RECT>::ToString(si.GetViewport().ToInclusive()).GetBuffer()));
38603871

3861-
VERIFY_ARE_EQUAL(4, cursor.GetPosition().X);
3872+
// Verify cursor moved to left margin.
3873+
VERIFY_ARE_EQUAL(0, cursor.GetPosition().X);
38623874
VERIFY_ARE_EQUAL(1, cursor.GetPosition().Y);
38633875
{
38643876
auto iter0 = tbi.GetCellDataAt({ 0, 0 });

0 commit comments

Comments
 (0)