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

Code before:
            co_return;
        }

        // If it's already open, then just re-target it and update
        // the content immediately. Otherwise:
        // wait a bit before opening it.
        if (_descriptionsView().Visibility() != Visibility::Visible)
        {
            co_await winrt::resume_after(200ms);
            co_await wil::resume_foreground(Dispatcher());
        }

        // Build the contents of the "tooltip" based on the description
        //
        // First, the title. This is just the name of the command.
        _descriptionTitle().Inlines().Clear();
        Documents::Run titleRun;
        titleRun.Text(cmd.Name());
        _descriptionTitle().Inlines().Append(titleRun);

        // Now fill up the "subtitle" part of the "tooltip" with the actual
        // description itself.
        _descriptionComment().Inlines().Clear();

        // First, replace all "\r\n" with "\n"
        std::wstring filtered = description.c_str();
        std::wstring::size_type pos = 0;
        while ((pos = filtered.find(L"\r\n", pos)) != std::wstring::npos)
        {
            filtered.erase(pos, 1);
        }

        // Split the filtered description on '\n`
        const auto lines = ::Microsoft::Console::Utils::SplitString(filtered.c_str(), L'\n');
        // build a Run + LineBreak, and add them to the text block
        for (const auto& line : lines)
        {
            if (line.empty())
            {
                continue;
            }
            Documents::Run textRun;
            textRun.Text(winrt::hstring{ line });
            _descriptionComment().Inlines().Append(textRun);
            _descriptionComment().Inlines().Append(Documents::LineBreak{});
        }

        // Now, make ourselves visible.
        _descriptionsView().Visibility(Visibility::Visible);
        _descriptionsBackdrop().Visibility(Visibility::Visible);
        // and update the padding to account for our new contents.

Review comment (suggestion):
You can cast `hstring` to a `wstring_view` to make this work.

Code after:
            return;
        }

        // Build the contents of the "tooltip" based on the description
        //
        // First, the title. This is just the name of the command.
        _descriptionTitle().Inlines().Clear();
        Documents::Run titleRun;
        titleRun.Text(cmd.Name());
        _descriptionTitle().Inlines().Append(titleRun);

        // Now fill up the "subtitle" part of the "tooltip" with the actual
        // description itself.
        const auto& inlines{ _descriptionComment().Inlines() };
        inlines.Clear();

        // Split the filtered description on '\n`
        const auto lines = ::Microsoft::Console::Utils::SplitString(description, L'\n');
        // build a Run + LineBreak, and add them to the text block
        for (const auto& line : lines)
        {
            // Trim off any `\r`'s in the string. Pwsh completions will
            // frequently have these embedded.
            std::wstring trimmed{ line };
            trimmed.erase(std::remove(trimmed.begin(), trimmed.end(), L'\r'), trimmed.end());
            if (trimmed.empty())
            {
                continue;
            }

            Documents::Run textRun;
            textRun.Text(trimmed);
            inlines.Append(textRun);
            inlines.Append(Documents::LineBreak{});
        }

        // Now, make ourselves visible.
        _descriptionsView().Visibility(Visibility::Visible);
        _descriptionsBackdrop().Visibility(Visibility::Visible);
        // and update the padding to account for our new contents.
        _recalculateTopMargin();
        return;
    }

    void SuggestionsControl::_previewKeyDownHandler(const IInspectable& /*sender*/,
                                                    const Windows::UI::Xaml::Input::KeyRoutedEventArgs& e)
    {
        const auto key = e.OriginalKey();
        const auto coreWindow = CoreWindow::GetForCurrentThread();
        const auto ctrlDown = WI_IsFlagSet(coreWindow.GetKeyState(winrt::Windows::System::VirtualKey::Control), CoreVirtualKeyStates::Down);