Skip to content

Commit f86d02e

Browse files
PankajBhojwaniminiksa
authored andcommitted
Fix mouse coordinates when viewport is scrolled for all events, not just pressed (#11290)
Does the mouse coordinate adjustment added in #10642 for all the other mouse events as well (moved, released, wheel) Closes #10190
1 parent 39a5b27 commit f86d02e

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

src/cascadia/TerminalControl/ControlInteractivity.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
182182
}
183183
else if (_canSendVTMouseInput(modifiers))
184184
{
185-
const auto adjustment = _core->ScrollOffset() > 0 ? _core->BufferHeight() - _core->ScrollOffset() - _core->ViewHeight() : 0;
186-
// If the click happened outside the active region, just don't send any mouse event
187-
if (const auto adjustedY = terminalPosition.y() - adjustment; adjustedY >= 0)
188-
{
189-
_core->SendMouseEvent({ terminalPosition.x(), adjustedY }, pointerUpdateKind, modifiers, 0, buttonState);
190-
}
185+
_sendMouseEventHelper(terminalPosition, pointerUpdateKind, modifiers, 0, buttonState);
191186
}
192187
else if (buttonState.isLeftButtonDown)
193188
{
@@ -254,7 +249,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
254249
// Short-circuit isReadOnly check to avoid warning dialog
255250
if (focused && !_core->IsInReadOnlyMode() && _canSendVTMouseInput(modifiers))
256251
{
257-
_core->SendMouseEvent(terminalPosition, pointerUpdateKind, modifiers, 0, buttonState);
252+
_sendMouseEventHelper(terminalPosition, pointerUpdateKind, modifiers, 0, buttonState);
258253
}
259254
else if (focused && buttonState.isLeftButtonDown)
260255
{
@@ -333,7 +328,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
333328
// Short-circuit isReadOnly check to avoid warning dialog
334329
if (!_core->IsInReadOnlyMode() && _canSendVTMouseInput(modifiers))
335330
{
336-
_core->SendMouseEvent(terminalPosition, pointerUpdateKind, modifiers, 0, buttonState);
331+
_sendMouseEventHelper(terminalPosition, pointerUpdateKind, modifiers, 0, buttonState);
337332
return;
338333
}
339334

@@ -383,11 +378,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
383378
// here with a PointerPoint. However, as of #979, we don't have a
384379
// PointerPoint to work with. So, we're just going to do a
385380
// mousewheel event manually
386-
return _core->SendMouseEvent(terminalPosition,
381+
return _sendMouseEventHelper(terminalPosition,
387382
WM_MOUSEWHEEL,
388383
modifiers,
389384
::base::saturated_cast<short>(delta),
390-
state);
385+
buttonState);
391386
}
392387

393388
const auto ctrlPressed = modifiers.IsCtrlPressed();
@@ -562,4 +557,20 @@ namespace winrt::Microsoft::Terminal::Control::implementation
562557
// Convert the location in pixels to characters within the current viewport.
563558
return til::point{ pixelPosition / fontSize };
564559
}
560+
561+
bool ControlInteractivity::_sendMouseEventHelper(const til::point terminalPosition,
562+
const unsigned int pointerUpdateKind,
563+
const ::Microsoft::Terminal::Core::ControlKeyStates modifiers,
564+
const SHORT wheelDelta,
565+
Control::MouseButtonState buttonState)
566+
{
567+
const auto adjustment = _core->ScrollOffset() > 0 ? _core->BufferHeight() - _core->ScrollOffset() - _core->ViewHeight() : 0;
568+
// If the click happened outside the active region, just don't send any mouse event
569+
if (const auto adjustedY = terminalPosition.y() - adjustment; adjustedY >= 0)
570+
{
571+
return _core->SendMouseEvent({ terminalPosition.x(), adjustedY }, pointerUpdateKind, modifiers, wheelDelta, toInternalMouseState(buttonState));
572+
}
573+
return false;
574+
}
575+
565576
}

src/cascadia/TerminalControl/ControlInteractivity.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation
132132
TYPED_EVENT(OpenHyperlink, IInspectable, Control::OpenHyperlinkEventArgs);
133133
TYPED_EVENT(PasteFromClipboard, IInspectable, Control::PasteFromClipboardEventArgs);
134134
TYPED_EVENT(ScrollPositionChanged, IInspectable, Control::ScrollPositionChangedArgs);
135+
136+
bool _sendMouseEventHelper(const til::point terminalPosition,
137+
const unsigned int pointerUpdateKind,
138+
const ::Microsoft::Terminal::Core::ControlKeyStates modifiers,
139+
const SHORT wheelDelta,
140+
Control::MouseButtonState buttonState);
135141

136142
friend class ControlUnitTests::ControlCoreTests;
137143
friend class ControlUnitTests::ControlInteractivityTests;

0 commit comments

Comments
 (0)