Skip to content

Commit

Permalink
fix clamping the selection at top/bottom properly
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora committed Jun 24, 2022
1 parent 32ca437 commit 0c5a1e9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/cascadia/TerminalCore/TerminalSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ void Terminal::UpdateSelection(SelectionDirection direction, SelectionExpansion
}
auto targetPos{ WI_IsFlagSet(_selectionEndpoint, SelectionEndpoint::Start) ? _selection->start : _selection->end };

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

// 2.B) Clamp the movement to the mutable viewport
targetPos = std::min(targetPos, _GetMutableViewport().BottomRightInclusive());

// 3. Actually modify the selection state
_selectionMode = std::max(_selectionMode, SelectionInteractionMode::Keyboard);
if (_selectionMode == SelectionInteractionMode::Mark && !mods.IsShiftPressed())
Expand Down Expand Up @@ -471,13 +468,16 @@ void Terminal::_MoveByChar(SelectionDirection direction, til::point& pos)
case SelectionDirection::Up:
{
const auto bufferSize{ _activeBuffer().GetSize() };
pos = { pos.X, std::clamp(pos.Y - 1, bufferSize.Top(), bufferSize.BottomInclusive()) };
const auto newY{ pos.Y - 1 };
pos = newY < bufferSize.Top() ? bufferSize.Origin() : til::point{ pos.X, newY };
break;
}
case SelectionDirection::Down:
{
const auto bufferSize{ _activeBuffer().GetSize() };
pos = { pos.X, std::clamp(pos.Y + 1, bufferSize.Top(), bufferSize.BottomInclusive()) };
const auto mutableBottom{ _GetMutableViewport().BottomInclusive() };
const auto newY{ pos.Y + 1 };
pos = newY > mutableBottom ? til::point{ bufferSize.RightInclusive(), mutableBottom } : til::point{ pos.X, newY };
break;
}
}
Expand Down

0 comments on commit 0c5a1e9

Please sign in to comment.