diff --git a/src/cascadia/TerminalCore/TerminalSelection.cpp b/src/cascadia/TerminalCore/TerminalSelection.cpp index 135dd39422b..9ffe27d1a27 100644 --- a/src/cascadia/TerminalCore/TerminalSelection.cpp +++ b/src/cascadia/TerminalCore/TerminalSelection.cpp @@ -325,7 +325,7 @@ void Terminal::UpdateSelection(SelectionDirection direction, SelectionExpansion const auto movingEnd{ _markMode ? mods.IsShiftPressed() : _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: @@ -342,6 +342,9 @@ 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 // NOTE: targetStart doesn't matter here if (_markMode) @@ -363,9 +366,9 @@ void Terminal::UpdateSelection(SelectionDirection direction, SelectionExpansion } // 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; @@ -373,7 +376,7 @@ void Terminal::UpdateSelection(SelectionDirection direction, SelectionExpansion else { // anchor is below visible viewport, scroll by that amount - const auto amtBelowView = targetPos.Y - viewport.BottomInclusive(); + const auto amtBelowView = targetPos.Y - visibleViewport.BottomInclusive(); _scrollOffset -= amtBelowView; } _NotifyScrollEvent();