From 1d21368e6eb85748dd489648326242a1fd184fb1 Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Fri, 17 Jun 2022 13:44:36 -0700 Subject: [PATCH 1/4] Fix moving selection past scroll area --- .../TerminalCore/TerminalSelection.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/cascadia/TerminalCore/TerminalSelection.cpp b/src/cascadia/TerminalCore/TerminalSelection.cpp index 135dd39422b..b733ca75436 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,17 @@ void Terminal::UpdateSelection(SelectionDirection direction, SelectionExpansion break; } + // 2.B) Clamp the movement to the mutable viewport + const auto mutableViewport{ _GetMutableViewport() }; + if (targetPos > mutableViewport.BottomRightInclusive()) + { + targetPos = mutableViewport.BottomRightInclusive(); + } + else if (targetPos < mutableViewport.Origin()) + { + targetPos = mutableViewport.Origin(); + } + // 3. Actually modify the selection // NOTE: targetStart doesn't matter here if (_markMode) @@ -363,9 +374,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 +384,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(); From ea6b0006631be7f69830a4836d48eda83b0a8045 Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Tue, 21 Jun 2022 11:04:56 -0700 Subject: [PATCH 2/4] only clamp Y-coord (and properly) --- src/cascadia/TerminalCore/TerminalSelection.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/cascadia/TerminalCore/TerminalSelection.cpp b/src/cascadia/TerminalCore/TerminalSelection.cpp index b733ca75436..a503296ff34 100644 --- a/src/cascadia/TerminalCore/TerminalSelection.cpp +++ b/src/cascadia/TerminalCore/TerminalSelection.cpp @@ -343,14 +343,13 @@ void Terminal::UpdateSelection(SelectionDirection direction, SelectionExpansion } // 2.B) Clamp the movement to the mutable viewport - const auto mutableViewport{ _GetMutableViewport() }; - if (targetPos > mutableViewport.BottomRightInclusive()) + if (const auto mutableViewport = _GetMutableViewport(); targetPos > mutableViewport.BottomRightInclusive()) { - targetPos = mutableViewport.BottomRightInclusive(); + targetPos.Y = mutableViewport.BottomInclusive(); } - else if (targetPos < mutableViewport.Origin()) + else if (const auto bufferSize = _activeBuffer().GetSize(); targetPos < bufferSize.Origin()) { - targetPos = mutableViewport.Origin(); + targetPos.Y = bufferSize.Top(); } // 3. Actually modify the selection From fd9ff02c18e43cd30286261df5de1c9fc3088467 Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Tue, 21 Jun 2022 15:40:14 -0700 Subject: [PATCH 3/4] move me to the corners --- src/cascadia/TerminalCore/TerminalSelection.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/cascadia/TerminalCore/TerminalSelection.cpp b/src/cascadia/TerminalCore/TerminalSelection.cpp index a503296ff34..39a6370d482 100644 --- a/src/cascadia/TerminalCore/TerminalSelection.cpp +++ b/src/cascadia/TerminalCore/TerminalSelection.cpp @@ -345,11 +345,7 @@ void Terminal::UpdateSelection(SelectionDirection direction, SelectionExpansion // 2.B) Clamp the movement to the mutable viewport if (const auto mutableViewport = _GetMutableViewport(); targetPos > mutableViewport.BottomRightInclusive()) { - targetPos.Y = mutableViewport.BottomInclusive(); - } - else if (const auto bufferSize = _activeBuffer().GetSize(); targetPos < bufferSize.Origin()) - { - targetPos.Y = bufferSize.Top(); + targetPos = mutableViewport.BottomRightInclusive(); } // 3. Actually modify the selection From a451b2c94a62a9a7e285673566006a2a8662925e Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Tue, 21 Jun 2022 17:05:09 -0700 Subject: [PATCH 4/4] use std::min --- src/cascadia/TerminalCore/TerminalSelection.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/cascadia/TerminalCore/TerminalSelection.cpp b/src/cascadia/TerminalCore/TerminalSelection.cpp index 39a6370d482..9ffe27d1a27 100644 --- a/src/cascadia/TerminalCore/TerminalSelection.cpp +++ b/src/cascadia/TerminalCore/TerminalSelection.cpp @@ -343,10 +343,7 @@ void Terminal::UpdateSelection(SelectionDirection direction, SelectionExpansion } // 2.B) Clamp the movement to the mutable viewport - if (const auto mutableViewport = _GetMutableViewport(); targetPos > mutableViewport.BottomRightInclusive()) - { - targetPos = mutableViewport.BottomRightInclusive(); - } + targetPos = std::min(targetPos, _GetMutableViewport().BottomRightInclusive()); // 3. Actually modify the selection // NOTE: targetStart doesn't matter here