Skip to content

Commit

Permalink
[1.14] Properly fix keyboard sln at top/bot (#13372)
Browse files Browse the repository at this point in the history
A port of commit 0c5a1e9 from #13358.
This fixes an oversight from #13353. That ended up not fixing when trying to move past the top boundary.
This is also a better fix overall. By moving the fix to `_MoveByChar`, we have consistency between all the `_MoveByX` functions in that they automatically clamp to be within the scroll area.
  • Loading branch information
carlos-zamora authored Jun 30, 2022
1 parent 7506a3a commit b796060
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 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.A) Perform the movement
// 2 Perform the movement
switch (mode)
{
case SelectionExpansion::Char:
Expand All @@ -305,15 +305,6 @@ 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;
Expand Down Expand Up @@ -362,13 +353,16 @@ void Terminal::_MoveByChar(SelectionDirection direction, COORD& pos)
case SelectionDirection::Up:
{
const auto bufferSize{ _activeBuffer().GetSize() };
pos = { pos.X, std::clamp(base::ClampSub<short, short>(pos.Y, 1).RawValue(), bufferSize.Top(), bufferSize.BottomInclusive()) };
const auto newY{ base::ClampSub<short, short>(pos.Y, 1).RawValue() };
pos = newY < bufferSize.Top() ? bufferSize.Origin() : COORD{ pos.X, newY };
break;
}
case SelectionDirection::Down:
{
const auto bufferSize{ _activeBuffer().GetSize() };
pos = { pos.X, std::clamp(base::ClampAdd<short, short>(pos.Y, 1).RawValue(), bufferSize.Top(), bufferSize.BottomInclusive()) };
const auto mutableBottom{ _GetMutableViewport().BottomInclusive() };
const auto newY{ base::ClampAdd<short, short>(pos.Y, 1).RawValue() };
pos = newY > mutableBottom ? COORD{ bufferSize.RightInclusive(), mutableBottom } : COORD{ pos.X, newY };
break;
}
}
Expand Down

0 comments on commit b796060

Please sign in to comment.