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

Code before:
        const auto windowId{ winrt::unbox_value<winrt::hstring>(windowIdObj) };

        // Convert the windowId to a number
        uint32_t src;
        if (!Utils::StringToUint(windowId.c_str(), src))
        {
            // Failed to convert the windowId to a number. Bail.
            co_return;
        }

        // Figure out where in the tab strip we're dropping this tab. Add that
        // index to the request. This is largely taken from the WinUI sample
        // app.

        // We need to be on OUR UI thread to figure out where we dropped
        auto weakThis{ get_weak() };
        co_await wil::resume_foreground(Dispatcher());
        if (const auto& page{ weakThis.get() })
        {
            // First we need to get the position in the List to drop to
            auto index = -1;

            // Determine which items in the list our pointer is between.
            for (auto i = 0u; i < _tabView.TabItems().Size(); i++)
            {
                if (auto item{ _tabView.ContainerFromIndex(i).try_as<winrt::MUX::Controls::TabViewItem>() })
                {
                    const auto posX{ e.GetPosition(item).X };
                    const auto itemWidth{ item.ActualWidth() };
                    if (posX - itemWidth < 0)
                    {
                        index = i;
                        break;
                    }
                }
            }

            // `this` is safe to use
            const auto request = winrt::make_self<RequestReceiveContentArgs>(src, _WindowProperties.WindowId(), index);

            // This will go up to the monarch, who will then dispatch the request
            // back down to the source TerminalPage, who will then perform a
            // RequestMoveContent to move their tab to us.
            _RequestReceiveContentHandlers(*this, *request);
        }
    }

    // Method Description:
    // - This is called on the drag/drop SOURCE TerminalPage, when the monarch has
    //   requested that we send our tab to another window. We'll need to
    //   serialize the tab, and send it to the monarch, who will then send it to

Review comment (suggestion):
```suggestion
                if (const auto item{ _tabView.ContainerFromIndex(i).try_as<winrt::MUX::Controls::TabViewItem>() })
```

Code after:
            // DON'T display the confirmation if this is the name we were
            // given on startup!
            if (page->_startupState == StartupState::Initialized)
            {
                page->IdentifyWindow();
            }
        }
    }

    void TerminalPage::_onTabDragStarting(const winrt::Microsoft::UI::Xaml::Controls::TabView&,
                                          const winrt::Microsoft::UI::Xaml::Controls::TabViewTabDragStartingEventArgs& e)
    {
        // Get the tab impl from this event.
        const auto eventTab = e.Tab();
        const auto tabBase = _GetTabByTabViewItem(eventTab);
        winrt::com_ptr<TabBase> tabImpl;
        tabImpl.copy_from(winrt::get_self<TabBase>(tabBase));
        if (tabImpl)
        {
            // First: stash the tab we started dragging.
            // We're going to be asked for this.
            _stashedDraggedTab = tabImpl;

            // Into the DataPackage, let's stash our own window ID.
            const auto id{ _WindowProperties.WindowId() };

            // Get our PID
            const auto pid{ GetCurrentProcessId() };

            e.Data().Properties().Insert(L"windowId", winrt::box_value(id));
            e.Data().Properties().Insert(L"pid", winrt::box_value<uint32_t>(pid));
            e.Data().RequestedOperation(DataPackageOperation::Move);

            // The next thing that will happen:
            //  * Another TerminalPage will get a TabStripDragOver, then get a
            //    TabStripDrop
            //    * This will be handled by the _other_ page asking the monarch
            //      to ask us to send our content to them.
            //  * We'll get a TabDroppedOutside to indicate that this tab was
            //    dropped _not_ on a TabView.
            //    * This we can't handle yet, and is the last point of TODO GH#5000
        }
    }

    void TerminalPage::_onTabStripDragOver(const winrt::Windows::Foundation::IInspectable& /*sender*/,
                                           const winrt::Windows::UI::Xaml::DragEventArgs& e)
    {
        // We must mark that we can accept the drag/drop. The system will never
        // call TabStripDrop on us if we don't indicate that we're willing.
        const auto& props{ e.DataView().Properties() };
        if (props.HasKey(L"windowId") &&