Repository: microsoft/terminal
File: src/cascadia/TerminalControl/ControlInteractivity.cpp (C++)

Code before:
                _singleClickTouchdownPos = std::nullopt;
            }
        }
        else if (WI_IsFlagSet(buttonState, MouseButtonState::IsRightButtonDown))
        {
            if (_core->CopyOnSelect())
            {
                // CopyOnSelect:
                // 1. keyboard selection? --> copy the new content first
                // 2. right click always pastes!
                if (_core->SelectionMode() > SelectionInteractionMode::Keyboard)
                {
                    CopySelectionToClipboard(shiftEnabled, nullptr);
                }
                RequestPasteTextFromClipboard();
            }
            else if (_core->HasSelection())
            {
                // copy selected text
                CopySelectionToClipboard(shiftEnabled, nullptr);
            }
            else
            {
                // no selection --> paste
                RequestPasteTextFromClipboard();
            }
        }
    }

    void ControlInteractivity::TouchPressed(const Core::Point contactPoint)
    {
        _touchAnchor = contactPoint;
    }

    void ControlInteractivity::PointerMoved(Control::MouseButtonState buttonState,
                                            const unsigned int pointerUpdateKind,
                                            const ::Microsoft::Terminal::Core::ControlKeyStates modifiers,
                                            const bool focused,
                                            const Core::Point pixelPosition,
                                            const bool pointerPressedInBounds)
    {
        const auto terminalPosition = _getTerminalPosition(til::point{ pixelPosition });

        // Short-circuit isReadOnly check to avoid warning dialog
        if (focused && !_core->IsInReadOnlyMode() && _canSendVTMouseInput(modifiers))
        {
            _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
        // a file into the bounds of the control. That shouldn't send the

Review comment (suggestion):
Hmm.

This conditional seems like it could be simplified.

```
if (A)
  if (C)
    X
  Y
else if (B)
  X
else
  Y
```


perhaps it can't, but there's a lot of redundancy in the body...

Code after:
        }
        else if (WI_IsFlagSet(buttonState, MouseButtonState::IsRightButtonDown))
        {
            // Try to copy the text and clear the selection
            const auto successfulCopy = CopySelectionToClipboard(shiftEnabled, nullptr);
            _core->ClearSelection();
            if (_core->CopyOnSelect() || !successfulCopy)
            {
                // CopyOnSelect: right click always pastes!
                // Otherwise: no selection --> paste
                RequestPasteTextFromClipboard();
            }
        }
    }

    void ControlInteractivity::TouchPressed(const Core::Point contactPoint)
    {
        _touchAnchor = contactPoint;
    }

    void ControlInteractivity::PointerMoved(Control::MouseButtonState buttonState,
                                            const unsigned int pointerUpdateKind,
                                            const ::Microsoft::Terminal::Core::ControlKeyStates modifiers,
                                            const bool focused,
                                            const Core::Point pixelPosition,
                                            const bool pointerPressedInBounds)
    {
        const auto terminalPosition = _getTerminalPosition(til::point{ pixelPosition });

        // Short-circuit isReadOnly check to avoid warning dialog
        if (focused && !_core->IsInReadOnlyMode() && _canSendVTMouseInput(modifiers))
        {
            _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
        // a file into the bounds of the control. That shouldn't send the
        // selection into space.
        else if (focused && pointerPressedInBounds && WI_IsFlagSet(buttonState, MouseButtonState::IsLeftButtonDown))
        {
            if (_singleClickTouchdownPos)
            {
                // Figure out if the user's moved a 1/4th of a cell's smaller axis
                // (practically always the width) away from the clickdown point.
                const auto fontSizeInDips = _core->FontSizeInDips();
                const auto touchdownPoint = *_singleClickTouchdownPos;
                const auto dx = pixelPosition.X - touchdownPoint.X;
                const auto dy = pixelPosition.Y - touchdownPoint.Y;
                const auto w = fontSizeInDips.width;
                const auto distanceSquared = dx * dx + dy * dy;
                const auto maxDistanceSquared = w * w / 16; // (w / 4)^2