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

Code before:
        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.
        _recalculateTopMargin();
        co_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);

        if (key == VirtualKey::Home && ctrlDown)
        {
            ScrollToTop();
            e.Handled(true);
        }
        else if (key == VirtualKey::End && ctrlDown)

Review comment (refactor):
I don't think you need to explicitly wrap `line` in an `hstring`.
This is only necessary for the `til` helpers and macros that we built ourselves, because we don't properly use `winrt::param::hstring`. But otherwise?

Code after:
        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);

        if (key == VirtualKey::Home && ctrlDown)
        {
            ScrollToTop();
            e.Handled(true);
        }
        else if (key == VirtualKey::End && ctrlDown)
        {
            ScrollToBottom();
            e.Handled(true);
        }
        else if (key == VirtualKey::Up)
        {
            // Move focus to the next item in the list.
            SelectNextItem(false);
            e.Handled(true);
        }
        else if (key == VirtualKey::Down)