Skip to content

Commit

Permalink
This fixes #9109
Browse files Browse the repository at this point in the history
  This is kind of annoying that the auto-scrolling is handled by the
  TermControl, but it uses a timer that's still a WinUI construct.

  We only want to start the auto-scrolling behavior when the drag started
  _inside_ the control. Otherwise, in the tab drag scenario, dragging into the
  bounds of the TermControl will trick it into thinking it should start a
  scroll.
  • Loading branch information
zadjii-msft committed Jul 13, 2021
1 parent 5a598f7 commit 6206d77
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
Focus(FocusState::Pointer);
}

_pointerPressedInBounds = true;

if (type == Windows::Devices::Input::PointerDeviceType::Touch)
{
const auto contactRect = point.Properties().ContactRect();
Expand Down Expand Up @@ -1103,8 +1105,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_focused,
pixelPosition);

if (_focused && point.Properties().IsLeftButtonPressed())
if (_focused && _pointerPressedInBounds && point.Properties().IsLeftButtonPressed())
{
// We want to find the distance relative to the bounds of the
// SwapChainPanel, not the entire control. If they drag out of
// the bounds of the text, into the padding, we still what that
// to auto-scroll
const double cursorBelowBottomDist = cursorPosition.Y - SwapChainPanel().Margin().Top - SwapChainPanel().ActualHeight();
const double cursorAboveTopDist = -1 * cursorPosition.Y + SwapChainPanel().Margin().Top;

Expand Down Expand Up @@ -1154,6 +1160,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return;
}

_pointerPressedInBounds = false;

const auto ptr = args.Pointer();
const auto point = args.GetCurrentPoint(*this);
const auto cursorPosition = point.Position();
Expand Down
4 changes: 3 additions & 1 deletion src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,13 @@ namespace winrt::Microsoft::Terminal::Control::implementation
std::shared_ptr<ThrottledFuncTrailing<ScrollBarUpdate>> _updateScrollBar;
bool _isInternalScrollBarUpdate;

// Auto scroll occurs when user, while selecting, drags cursor outside viewport. View is then scrolled to 'follow' the cursor.
// Auto scroll occurs when user, while selecting, drags cursor outside
// viewport. View is then scrolled to 'follow' the cursor.
double _autoScrollVelocity;
std::optional<Windows::UI::Input::PointerPoint> _autoScrollingPointerPoint;
Windows::UI::Xaml::DispatcherTimer _autoScrollTimer;
std::optional<std::chrono::high_resolution_clock::time_point> _lastAutoScrollUpdateTime;
bool _pointerPressedInBounds{ false };

winrt::Windows::UI::Composition::ScalarKeyFrameAnimation _bellLightAnimation{ nullptr };
Windows::UI::Xaml::DispatcherTimer _bellLightTimer{ nullptr };
Expand Down

0 comments on commit 6206d77

Please sign in to comment.