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

Code before:
    Windows::Foundation::IAsyncAction TerminalPage::_SearchMissingCommandHandler(const IInspectable /*sender*/, const Microsoft::Terminal::Control::SearchMissingCommandEventArgs args)
    {
        assert(!Dispatcher().HasThreadAccess());

        if (!Feature_QuickFix::IsEnabled())
        {
            co_return;
        }

        auto pkgList = co_await _FindPackageAsync(args.MissingCommand());
        for (int retries = 0; !pkgList && retries < 3; ++retries)
        {
            pkgList = co_await _FindPackageAsync(args.MissingCommand());
        }

        // no packages were found, nothing to suggest
        if (pkgList.Size() == 0)
        {
            co_return;
        }

        std::vector<hstring> suggestions;
        suggestions.reserve(pkgList.Size());
        for (auto pkg : pkgList)
        {
            suggestions.emplace_back(fmt::format(FMT_COMPILE(L"winget install --id {}"), pkg.CatalogPackage().Id()));
        }

        co_await wil::resume_foreground(Dispatcher());

        auto term = _GetActiveControl();
        if (!term)
        {
            co_return;
        }
        term.UpdateWinGetSuggestions(single_threaded_vector<hstring>(std::move(suggestions)));
        term.RefreshQuickFixMenu();
    }

    // Method Description:
    // - Paste text from the Windows Clipboard to the focused terminal
    void TerminalPage::_PasteText()
    {
        // First, check if we're in broadcast input mode. If so, let's tell all
        // the controls to paste.
        if (const auto& tab{ _GetFocusedTabImpl() })
        {
            if (tab->TabStatus().IsInputBroadcastActive())
            {
                tab->GetRootPane()->WalkTree([](auto&& pane) {
                    if (auto control = pane->GetTerminalControl())

Review comment (suggestion):
```suggestion
            suggestions.emplace_back(fmt::format(FMT_COMPILE(L"winget install -s winget --id {}"), pkg.CatalogPackage().Id()));
```
Without the source parameter, the id could collide with another package catalog.

Code after:
            filter.Field(search.Field);
            filter.Option(search.MatchOption);

            const auto result = co_await catalog.FindPackagesAsync(options);
            pkgList = result.Matches();
            if (pkgList.Size() > 0)
            {
                break;
            }
        }
        co_return pkgList;
    }

    Windows::Foundation::IAsyncAction TerminalPage::_SearchMissingCommandHandler(const IInspectable /*sender*/, const Microsoft::Terminal::Control::SearchMissingCommandEventArgs args)
    {
        if (!Feature_QuickFix::IsEnabled())
        {
            co_return;
        }
        co_await winrt::resume_background();

        // no packages were found, nothing to suggest
        const auto pkgList = co_await _FindPackageAsync(args.MissingCommand());
        if (!pkgList || pkgList.Size() == 0)
        {
            co_return;
        }

        std::vector<hstring> suggestions;
        suggestions.reserve(pkgList.Size());
        for (const auto& pkg : pkgList)
        {
            // --id and --source ensure we don't collide with another package catalog
            suggestions.emplace_back(fmt::format(FMT_COMPILE(L"winget install --id {} -s winget"), pkg.CatalogPackage().Id()));
        }

        co_await wil::resume_foreground(Dispatcher());

        auto term = _GetActiveControl();
        if (!term)
        {
            co_return;
        }
        term.UpdateWinGetSuggestions(single_threaded_vector<hstring>(std::move(suggestions)));
        term.RefreshQuickFixMenu();
    }

    // Method Description:
    // - Paste text from the Windows Clipboard to the focused terminal
    void TerminalPage::_PasteText()
    {