Repository: microsoft/terminal
File: src/cascadia/TerminalApp/TabManagement.cpp (C++)

Code before:
    {
        if (_rearranging)
        {
            if (eventArgs.CollectionChange() == Windows::Foundation::Collections::CollectionChange::ItemRemoved)
            {
                _rearrangeFrom = eventArgs.Index();
            }

            if (eventArgs.CollectionChange() == Windows::Foundation::Collections::CollectionChange::ItemInserted)
            {
                _rearrangeTo = eventArgs.Index();
            }
        }

        CommandPalette().Visibility(Visibility::Collapsed);
        _UpdateTabView();
    }

    // Method Description:
    // - Additional responses to clicking on a TabView's item. Currently, just remove tab with middle click
    // Arguments:
    // - sender: the control that originated this event (TabViewItem)
    // - eventArgs: the event's constituent arguments
    void TerminalPage::_OnPointerPressed(const IInspectable& sender, const Windows::UI::Xaml::Input::PointerRoutedEventArgs& eventArgs)
    {
        if (eventArgs.GetCurrentPoint(*this).Properties().IsMiddleButtonPressed())
        {
            if (const auto tabViewItem{ sender.try_as<MUX::Controls::TabViewItem>() })
            {
                _pointerMiddleButtonPressed = tabViewItem.CapturePointer(eventArgs.Pointer());
                _pointerMiddleButtonExited = false;
            }
            eventArgs.Handled(true);
        }
    }

    // Method Description:
    // - Tracking pointer state for tab remove
    // Arguments:
    // - sender: the control that originated this event (TabViewItem)
    // - eventArgs: the event's constituent arguments
    void TerminalPage::_OnPointerReleased(const IInspectable& sender, const Windows::UI::Xaml::Input::PointerRoutedEventArgs& eventArgs)
    {
        if (_pointerMiddleButtonPressed && !eventArgs.GetCurrentPoint(*this).Properties().IsMiddleButtonPressed())
        {
            _pointerMiddleButtonPressed = false;
            if (const auto tabViewItem{ sender.try_as<MUX::Controls::TabViewItem>() })
            {
                tabViewItem.ReleasePointerCapture(eventArgs.Pointer());
                auto tab = _GetTabByTabViewItem(tabViewItem);
                if (!_pointerMiddleButtonExited && tab)

Review comment (bug):
BTW shouldn't we pass `sender` instead of `*this` if anything? The documentation makes it sound like we can also just pass `nullptr` btw: https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.input.pointerroutedeventargs.getcurrentpoint

Code after:
    }

    // Method Description:
    // - Additional responses to clicking on a TabView's item. Currently, just remove tab with middle click
    // Arguments:
    // - sender: the control that originated this event (TabViewItem)
    // - eventArgs: the event's constituent arguments
    void TerminalPage::_OnTabPointerPressed(const IInspectable& sender, const Windows::UI::Xaml::Input::PointerRoutedEventArgs& eventArgs)
    {
        if (eventArgs.GetCurrentPoint(nullptr).Properties().IsMiddleButtonPressed())
        {
            if (const auto tabViewItem{ sender.try_as<MUX::Controls::TabViewItem>() })
            {
                _tabPointerMiddleButtonPressed = tabViewItem.CapturePointer(eventArgs.Pointer());
                _tabPointerMiddleButtonExited = false;
            }
            eventArgs.Handled(true);
        }
    }

    // Method Description:
    // - Tracking pointer state for tab remove
    // Arguments:
    // - sender: the control that originated this event (TabViewItem)
    // - eventArgs: the event's constituent arguments
    void TerminalPage::_OnTabPointerReleased(const IInspectable& sender, const Windows::UI::Xaml::Input::PointerRoutedEventArgs& eventArgs)
    {
        if (_tabPointerMiddleButtonPressed && !eventArgs.GetCurrentPoint(nullptr).Properties().IsMiddleButtonPressed())
        {
            _tabPointerMiddleButtonPressed = false;
            if (const auto tabViewItem{ sender.try_as<MUX::Controls::TabViewItem>() })
            {
                tabViewItem.ReleasePointerCapture(eventArgs.Pointer());
                auto tab = _GetTabByTabViewItem(tabViewItem);
                if (!_tabPointerMiddleButtonExited && tab)
                {
                    _HandleCloseTabRequested(tab);
                }
            }
            eventArgs.Handled(true);
        }
    }

    // Method Description:
    // - Tracking pointer state for tab remove
    // Arguments:
    // - sender: the control that originated this event (TabViewItem)
    // - eventArgs: the event's constituent arguments
    void TerminalPage::_OnTabPointerEntered(const IInspectable& /*sender*/, const Windows::UI::Xaml::Input::PointerRoutedEventArgs& eventArgs)
    {
        if (eventArgs.GetCurrentPoint(nullptr).Properties().IsMiddleButtonPressed())