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

Code before:

        // DON'T set up Toasts/TeachingTips here. They should be loaded and
        // initialized the first time they're opened, in whatever method opens
        // them.

        // Setup mouse vanish attributes
        SystemParametersInfoW(SPI_GETMOUSEVANISH, 0, &_shouldMouseVanish, false);

        // Store cursor, so we can restore it, e.g., after mouse vanishing
        // (we'll need to adapt this logic once we make cursor context aware)
        try
        {
            _defaultPointerCursor = CoreWindow::GetForCurrentThread().PointerCursor();
        }
        CATCH_LOG();
    }

    winrt::fire_and_forget TerminalPage::NewTerminalByDrop(winrt::Windows::UI::Xaml::DragEventArgs& e)
    {
        Windows::Foundation::Collections::IVectorView<Windows::Storage::IStorageItem> items;
        try
        {
            items = co_await e.DataView().GetStorageItemsAsync();
        }
        CATCH_LOG();

        if (items.Size() == 1)
        {
            std::filesystem::path path(items.GetAt(0).Path().c_str());
            if (!std::filesystem::is_directory(path))
            {
                path = path.parent_path();
            }

            std::wstring pathText = path.wstring();

            // Handle edge case of "C:\\", seems like the "StartingDirectory" doesn't like path which ends with '\'
            if (pathText.back() == L'\\')
            {
                pathText.erase(std::prev(pathText.end()));
            }

            NewTerminalArgs args;
            args.StartingDirectory(winrt::hstring{ pathText });
            this->_OpenNewTerminal(args);
        }
    }

    // Method Description:
    // - This method is called once command palette action was chosen for dispatching
    //   We'll use this event to dispatch this command.

Review comment (suggestion):
Wonder how well `std::filesystem::is_directory` handles UNC paths.

Code after:

        // Setup mouse vanish attributes
        SystemParametersInfoW(SPI_GETMOUSEVANISH, 0, &_shouldMouseVanish, false);

        // Store cursor, so we can restore it, e.g., after mouse vanishing
        // (we'll need to adapt this logic once we make cursor context aware)
        try
        {
            _defaultPointerCursor = CoreWindow::GetForCurrentThread().PointerCursor();
        }
        CATCH_LOG();
    }

    winrt::fire_and_forget TerminalPage::NewTerminalByDrop(winrt::Windows::UI::Xaml::DragEventArgs& e)
    {
        Windows::Foundation::Collections::IVectorView<Windows::Storage::IStorageItem> items;
        try
        {
            items = co_await e.DataView().GetStorageItemsAsync();
        }
        CATCH_LOG();

        if (items.Size() == 1)
        {
            std::filesystem::path path(items.GetAt(0).Path().c_str());
            if (!std::filesystem::is_directory(path))
            {
                path = path.parent_path();
            }

            std::wstring pathText = path.wstring();

            // Handle edge case of "C:\\", seems like the "StartingDirectory" doesn't like path which ends with '\'
            if (pathText.back() == L'\\')
            {
                pathText.erase(std::prev(pathText.end()));
            }

            NewTerminalArgs args;
            args.StartingDirectory(winrt::hstring{ pathText });
            this->_OpenNewTerminal(args);
        }
    }

    // Method Description:
    // - This method is called once command palette action was chosen for dispatching
    //   We'll use this event to dispatch this command.
    // Arguments:
    // - command - command to dispatch
    // Return Value:
    // - <none>