Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent the horizontal tab character wrapping at the end of a line #3197

Merged
merged 5 commits into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/host/_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,6 @@ using Microsoft::Console::VirtualTerminal::StateMachine;
if (screenInfo.InVTMode())
{
const COORD cCursorOld = cursor.GetPosition();
// Get Forward tab handles tabbing past the end of the buffer
CursorPosition = screenInfo.GetForwardTab(cCursorOld);
}
else
Expand Down
14 changes: 5 additions & 9 deletions src/host/getset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1567,19 +1567,15 @@ void DoSrvPrivateUseMainScreenBuffer(SCREEN_INFORMATION& screenInfo)
{
CONSOLE_INFORMATION& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
SCREEN_INFORMATION& _screenBuffer = gci.GetActiveOutputBuffer().GetActiveBuffer();
COORD cursorPos = _screenBuffer.GetTextBuffer().GetCursor().GetPosition();

NTSTATUS Status = STATUS_SUCCESS;
FAIL_FAST_IF(!(sNumTabs >= 0));
for (SHORT sTabsExecuted = 0; sTabsExecuted < sNumTabs && NT_SUCCESS(Status); sTabsExecuted++)
for (SHORT sTabsExecuted = 0; sTabsExecuted < sNumTabs; sTabsExecuted++)
{
const COORD cursorPos = _screenBuffer.GetTextBuffer().GetCursor().GetPosition();
COORD cNewPos = (fForward) ? _screenBuffer.GetForwardTab(cursorPos) : _screenBuffer.GetReverseTab(cursorPos);
// GetForwardTab is smart enough to move the cursor to the next line if
// it's at the end of the current one already. AdjustCursorPos shouldn't
// to be doing anything funny, just moving the cursor to the location GetForwardTab returns
Status = AdjustCursorPosition(_screenBuffer, cNewPos, TRUE, nullptr);
cursorPos = (fForward) ? _screenBuffer.GetForwardTab(cursorPos) : _screenBuffer.GetReverseTab(cursorPos);
}
return Status;

return AdjustCursorPosition(_screenBuffer, cursorPos, TRUE, nullptr);
}

// Routine Description:
Expand Down
10 changes: 3 additions & 7 deletions src/host/screenInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2219,12 +2219,7 @@ COORD SCREEN_INFORMATION::GetForwardTab(const COORD cCurrCursorPos) const noexce
{
COORD cNewCursorPos = cCurrCursorPos;
SHORT sWidth = GetBufferSize().RightInclusive();
if (cCurrCursorPos.X == sWidth)
{
cNewCursorPos.X = 0;
cNewCursorPos.Y += 1;
}
else if (_tabStops.empty() || cCurrCursorPos.X >= _tabStops.back())
if (_tabStops.empty() || cCurrCursorPos.X >= _tabStops.back())
{
cNewCursorPos.X = sWidth;
}
Expand All @@ -2235,7 +2230,8 @@ COORD SCREEN_INFORMATION::GetForwardTab(const COORD cCurrCursorPos) const noexce
{
if (*it > cCurrCursorPos.X)
{
cNewCursorPos.X = *it;
// make sure we don't exceed the width of the buffer
cNewCursorPos.X = std::min(*it, sWidth);
break;
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/host/ut_host/ScreenBufferTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,19 @@ void ScreenBufferTests::TestGetForwardTab()
L"Cursor advanced to end of screen buffer.");
}

Log::Comment(L"Find next tab from rightmost column.");
{
coordCursor.X = coordScreenBufferSize.X - 1;

COORD coordCursorExpected;
coordCursorExpected = coordCursor;

COORD const coordCursorResult = si.GetForwardTab(coordCursor);
VERIFY_ARE_EQUAL(coordCursorExpected,
coordCursorResult,
L"Cursor remains in rightmost column.");
}

si._tabStops.clear();
}

Expand Down