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

Correct the boundaries of the scrolling commands #2505

Merged
merged 7 commits into from
Sep 11, 2019
25 changes: 10 additions & 15 deletions src/host/getset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,24 +1356,22 @@ void DoSrvPrivateAllowCursorBlinking(SCREEN_INFORMATION& screenInfo, const bool
if (screenInfo.IsCursorInMargins(oldCursorPosition))
{
// Cursor is at the top of the viewport
const COORD bufferSize = screenInfo.GetBufferSize().Dimensions();
// Rectangle to cut out of the existing buffer
// Rectangle to cut out of the existing buffer. This is inclusive.
// It will be clipped to the buffer boundaries so SHORT_MAX gives us the full buffer width.
SMALL_RECT srScroll;
srScroll.Left = 0;
srScroll.Right = bufferSize.X;
srScroll.Right = SHORT_MAX;
j4james marked this conversation as resolved.
Show resolved Hide resolved
srScroll.Top = viewport.Top;
srScroll.Bottom = viewport.Bottom - 1;
srScroll.Bottom = viewport.Bottom;
j4james marked this conversation as resolved.
Show resolved Hide resolved
// Paste coordinate for cut text above
COORD coordDestination;
coordDestination.X = 0;
coordDestination.Y = viewport.Top + 1;

SMALL_RECT srClip = viewport;

Status = NTSTATUS_FROM_HRESULT(ServiceLocator::LocateGlobals().api.ScrollConsoleScreenBufferWImpl(screenInfo,
srScroll,
coordDestination,
srClip,
srScroll,
UNICODE_SPACE,
screenInfo.GetAttributes().GetLegacyAttributes()));
}
Expand Down Expand Up @@ -2033,13 +2031,13 @@ void DoSrvPrivateModifyLinesImpl(const unsigned int count, const bool insert)
const auto cursorPosition = textBuffer.GetCursor().GetPosition();
if (screenInfo.IsCursorInMargins(cursorPosition))
{
const auto screenEdges = screenInfo.GetBufferSize().ToInclusive();
// Rectangle to cut out of the existing buffer
// Rectangle to cut out of the existing buffer. This is inclusive.
// It will be clipped to the buffer boundaries so SHORT_MAX gives us the full buffer width.
SMALL_RECT srScroll;
srScroll.Left = 0;
srScroll.Right = screenEdges.Right - screenEdges.Left;
srScroll.Right = SHORT_MAX;
srScroll.Top = cursorPosition.Y;
srScroll.Bottom = screenEdges.Bottom;
srScroll.Bottom = screenInfo.GetViewport().BottomInclusive();
// Paste coordinate for cut text above
COORD coordDestination;
coordDestination.X = 0;
Expand All @@ -2052,9 +2050,6 @@ void DoSrvPrivateModifyLinesImpl(const unsigned int count, const bool insert)
coordDestination.Y = (cursorPosition.Y) - gsl::narrow<short>(count);
}

SMALL_RECT srClip = screenEdges;
srClip.Top = cursorPosition.Y;

// Here we previously called to ScrollConsoleScreenBufferWImpl to
// perform the scrolling operation. However, that function only accepts
// a WORD for the fill attributes. That means we'd lose 256/RGB fidelity
Expand All @@ -2068,7 +2063,7 @@ void DoSrvPrivateModifyLinesImpl(const unsigned int count, const bool insert)
auto Unlock = wil::scope_exit([&] { UnlockConsole(); });
ScrollRegion(screenInfo,
srScroll,
srClip,
srScroll,
coordDestination,
UNICODE_SPACE,
screenInfo.GetAttributes());
Expand Down
Loading