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

[1.14] Fix moving selection past scroll area #13353

Merged
merged 5 commits into from
Jun 22, 2022
Merged
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
17 changes: 13 additions & 4 deletions src/cascadia/TerminalCore/TerminalSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ void Terminal::UpdateSelection(SelectionDirection direction, SelectionExpansion
const auto movingEnd{ _selection->start == _selection->pivot };
auto targetPos{ movingEnd ? _selection->end : _selection->start };

// 2. Perform the movement
// 2.A) Perform the movement
switch (mode)
{
case SelectionExpansion::Char:
Expand All @@ -305,23 +305,32 @@ void Terminal::UpdateSelection(SelectionDirection direction, SelectionExpansion
break;
}

// 2.B) Clamp the movement to the mutable viewport
const auto bufferSize = _activeBuffer().GetSize();
const auto mutableViewport = _GetMutableViewport();
const COORD bottomRightInclusive{ mutableViewport.RightInclusive(), mutableViewport.BottomInclusive() };
if (bufferSize.CompareInBounds(targetPos, bottomRightInclusive) > 0)
{
targetPos = bottomRightInclusive;
}

// 3. Actually modify the selection
// NOTE: targetStart doesn't matter here
auto targetStart = false;
std::tie(_selection->start, _selection->end) = _PivotSelection(targetPos, targetStart);

// 4. Scroll (if necessary)
if (const auto viewport = _GetVisibleViewport(); !viewport.IsInBounds(targetPos))
if (const auto visibleViewport = _GetVisibleViewport(); !visibleViewport.IsInBounds(targetPos))
{
if (const auto amtAboveView = viewport.Top() - targetPos.Y; amtAboveView > 0)
if (const auto amtAboveView = visibleViewport.Top() - targetPos.Y; amtAboveView > 0)
{
// anchor is above visible viewport, scroll by that amount
_scrollOffset += amtAboveView;
}
else
{
// anchor is below visible viewport, scroll by that amount
const auto amtBelowView = targetPos.Y - viewport.BottomInclusive();
const auto amtBelowView = targetPos.Y - visibleViewport.BottomInclusive();
Comment on lines +323 to +333
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes appear unnecessary right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, they're more helpful on main than here. I just wanted to create more clarity to distinguish between the visible viewport and mutable viewport. I'll still keep it at least to keep things as consistent as possible between these two branches.

_scrollOffset -= amtBelowView;
}
_NotifyScrollEvent();
Expand Down