diff --git a/src/cascadia/TerminalControl/ControlInteractivity.cpp b/src/cascadia/TerminalControl/ControlInteractivity.cpp index 55d389869..6991d1b40 100644 --- a/src/cascadia/TerminalControl/ControlInteractivity.cpp +++ b/src/cascadia/TerminalControl/ControlInteractivity.cpp @@ -214,12 +214,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation } else if (_canSendVTMouseInput(modifiers)) { - const auto adjustment = _core->ScrollOffset() > 0 ? _core->BufferHeight() - _core->ScrollOffset() - _core->ViewHeight() : 0; - // If the click happened outside the active region, just don't send any mouse event - if (const auto adjustedY = terminalPosition.y() - adjustment; adjustedY >= 0) - { - _core->SendMouseEvent({ terminalPosition.x(), adjustedY }, pointerUpdateKind, modifiers, 0, toInternalMouseState(buttonState)); - } + _sendMouseEventHelper(terminalPosition, pointerUpdateKind, modifiers, 0, buttonState); } else if (WI_IsFlagSet(buttonState, MouseButtonState::IsLeftButtonDown)) { @@ -287,7 +282,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation // Short-circuit isReadOnly check to avoid warning dialog if (focused && !_core->IsInReadOnlyMode() && _canSendVTMouseInput(modifiers)) { - _core->SendMouseEvent(terminalPosition, pointerUpdateKind, modifiers, 0, toInternalMouseState(buttonState)); + _sendMouseEventHelper(terminalPosition, pointerUpdateKind, modifiers, 0, buttonState); } // GH#4603 - don't modify the selection if the pointer press didn't // actually start _in_ the control bounds. Case in point - someone drags @@ -370,7 +365,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation // Short-circuit isReadOnly check to avoid warning dialog if (!_core->IsInReadOnlyMode() && _canSendVTMouseInput(modifiers)) { - _core->SendMouseEvent(terminalPosition, pointerUpdateKind, modifiers, 0, toInternalMouseState(buttonState)); + _sendMouseEventHelper(terminalPosition, pointerUpdateKind, modifiers, 0, buttonState); return; } @@ -420,11 +415,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation // here with a PointerPoint. However, as of #979, we don't have a // PointerPoint to work with. So, we're just going to do a // mousewheel event manually - return _core->SendMouseEvent(terminalPosition, + return _sendMouseEventHelper(terminalPosition, WM_MOUSEWHEEL, modifiers, ::base::saturated_cast(delta), - toInternalMouseState(buttonState)); + buttonState); } const auto ctrlPressed = modifiers.IsCtrlPressed(); @@ -600,6 +595,21 @@ namespace winrt::Microsoft::Terminal::Control::implementation return til::point{ pixelPosition / fontSize }; } + bool ControlInteractivity::_sendMouseEventHelper(const til::point terminalPosition, + const unsigned int pointerUpdateKind, + const ::Microsoft::Terminal::Core::ControlKeyStates modifiers, + const SHORT wheelDelta, + Control::MouseButtonState buttonState) + { + const auto adjustment = _core->ScrollOffset() > 0 ? _core->BufferHeight() - _core->ScrollOffset() - _core->ViewHeight() : 0; + // If the click happened outside the active region, just don't send any mouse event + if (const auto adjustedY = terminalPosition.y() - adjustment; adjustedY >= 0) + { + return _core->SendMouseEvent({ terminalPosition.x(), adjustedY }, pointerUpdateKind, modifiers, wheelDelta, toInternalMouseState(buttonState)); + } + return false; + } + // Method Description: // - Creates an automation peer for the Terminal Control, enabling // accessibility on our control. diff --git a/src/cascadia/TerminalControl/ControlInteractivity.h b/src/cascadia/TerminalControl/ControlInteractivity.h index 937534838..71312afc3 100644 --- a/src/cascadia/TerminalControl/ControlInteractivity.h +++ b/src/cascadia/TerminalControl/ControlInteractivity.h @@ -142,6 +142,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation void _sendPastedTextToConnection(std::wstring_view wstr); til::point _getTerminalPosition(const til::point& pixelPosition); + bool _sendMouseEventHelper(const til::point terminalPosition, + const unsigned int pointerUpdateKind, + const ::Microsoft::Terminal::Core::ControlKeyStates modifiers, + const SHORT wheelDelta, + Control::MouseButtonState buttonState); + friend class ControlUnitTests::ControlCoreTests; friend class ControlUnitTests::ControlInteractivityTests; };