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

Code before:
        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 (const 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
    //   the destination window.
    // - Fortunately, sending the tab is basically just a MoveTab action, so we
    //   can largely reuse that.
    winrt::fire_and_forget TerminalPage::SendContentToOther(winrt::TerminalApp::RequestReceiveContentArgs args)

Review comment (suggestion):
oh interesting. I think we have an off by one! This explains my weird tab 1 concerns from above.

Dropping ANYWHERE to the left of tab 3's right edge

```
                      | here    |
                      v         v
/-----------,---------,---------\
|  pwsh     | oof     | barbaz  |
```

causes us to insert here:

```
                      | here
                      v
/-----------,---------,---------\
|  pwsh     | oof     | barbaz  |
```

Code after:
        // 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 (const auto& item{ _tabView.ContainerFromIndex(i).try_as<winrt::MUX::Controls::TabViewItem>() })
                {
                    const auto posX{ e.GetPosition(item).X }; // The point of the drop, relative to the tab
                    const auto itemWidth{ item.ActualWidth() }; // The right of the tab
                    // If the drag point is on the left half of the tab, then insert here.
                    if (posX < itemWidth / 2)
                    {
                        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
    //   the destination window.
    // - Fortunately, sending the tab is basically just a MoveTab action, so we
    //   can largely reuse that.
    winrt::fire_and_forget TerminalPage::SendContentToOther(winrt::TerminalApp::RequestReceiveContentArgs args)
    {
        // validate that we're the source window of the tab in this request
        if (args.SourceWindow() != _WindowProperties.WindowId())
        {
            co_return;
        }