From b054603f8490899bba81b718e3d9e4d233f0aafa Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Thu, 23 Jun 2022 17:48:59 -0700 Subject: [PATCH] [1.14] Properly fix keyboard sln at top/bot --- .../TerminalCore/TerminalSelection.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/cascadia/TerminalCore/TerminalSelection.cpp b/src/cascadia/TerminalCore/TerminalSelection.cpp index ad33e3f0b54..9651dc86a60 100644 --- a/src/cascadia/TerminalCore/TerminalSelection.cpp +++ b/src/cascadia/TerminalCore/TerminalSelection.cpp @@ -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: @@ -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; @@ -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(pos.Y, 1).RawValue(), bufferSize.Top(), bufferSize.BottomInclusive()) }; + const auto newY{ base::ClampSub(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(pos.Y, 1).RawValue(), bufferSize.Top(), bufferSize.BottomInclusive()) }; + const auto mutableBottom{ _GetMutableViewport().BottomInclusive() }; + const auto newY{ base::ClampAdd(pos.Y, 1).RawValue() }; + pos = newY > mutableBottom ? COORD{ bufferSize.RightInclusive(), mutableBottom } : COORD{ pos.X, newY }; break; } }