Repository: microsoft/terminal
File: src/cascadia/TerminalControl/TermControl.cpp (C++)

Code before:
        }
    }

    // Method Description:
    // - Writes the given sequence as input to the active terminal connection.
    // - This method has been overloaded to allow zero-copy winrt::param::hstring optimizations.
    // Arguments:
    // - wstr: the string of characters to write to the terminal connection.
    // Return Value:
    // - <none>
    void TermControl::_SendInputToConnection(const winrt::hstring& wstr)
    {
        _connection.WriteInput(wstr);
    }

    void TermControl::_SendInputToConnection(std::wstring_view wstr)
    {
        _connection.WriteInput(wstr);
    }

    // Method Description:
    // - Pre-process text pasted (presumably from the clipboard)
    //   before sending it over the terminal's connection.
    void TermControl::_SendPastedTextToConnection(const std::wstring& wstr)
    {
        auto option = ::Microsoft::Console::Utils::PasteOption::CarriageReturnNewline |
                      ::Microsoft::Console::Utils::PasteOption::FilterControlCodes;

        if (_terminal->IsXtermBracketedPasteModeEnabled())
        {
            WI_SetFlag(option, ::Microsoft::Console::Utils::PasteOption::Bracketed);
        }

        const auto converted = ::Microsoft::Console::Utils::ConvertPasteString(wstr, option);
        _connection.WriteInput(converted);
        _terminal->ClearSelection();
        _terminal->TrySnapOnInput();
    }

    // Method Description:
    // - Update the font with the renderer. This will be called either when the
    //      font changes or the DPI changes, as DPI changes will necessitate a
    //      font change. This method will *not* change the buffer/viewport size
    //      to account for the new glyph dimensions. Callers should make sure to
    //      appropriately call _DoResizeUnderLock after this method is called.
    // - The write lock should be held when calling this method.
    // Arguments:
    // - initialUpdate: whether this font update should be considered as being
    //   concerned with initialization process. Value forwarded to event handler.
    void TermControl::_UpdateFont(const bool initialUpdate)
    {

Review comment (suggestion):
We may want to introduce a function in TerminalCore like `WritePastedText` or `WriteTextFromClipboard` that handles everything in this function (except the wstring reference part. plz use a string_view :smile:)

This will let us reuse ALL of the logic for the WPF control!

Code after:
        }
    }

    // Method Description:
    // - Writes the given sequence as input to the active terminal connection.
    // - This method has been overloaded to allow zero-copy winrt::param::hstring optimizations.
    // Arguments:
    // - wstr: the string of characters to write to the terminal connection.
    // Return Value:
    // - <none>
    void TermControl::_SendInputToConnection(const winrt::hstring& wstr)
    {
        _connection.WriteInput(wstr);
    }

    void TermControl::_SendInputToConnection(std::wstring_view wstr)
    {
        _connection.WriteInput(wstr);
    }

    // Method Description:
    // - Pre-process text pasted (presumably from the clipboard)
    //   before sending it over the terminal's connection.
    void TermControl::_SendPastedTextToConnection(const std::wstring& wstr)
    {
        _terminal->WritePastedText(wstr);
        _terminal->ClearSelection();
        _terminal->TrySnapOnInput();
    }

    // Method Description:
    // - Update the font with the renderer. This will be called either when the
    //      font changes or the DPI changes, as DPI changes will necessitate a
    //      font change. This method will *not* change the buffer/viewport size
    //      to account for the new glyph dimensions. Callers should make sure to
    //      appropriately call _DoResizeUnderLock after this method is called.
    // - The write lock should be held when calling this method.
    // Arguments:
    // - initialUpdate: whether this font update should be considered as being
    //   concerned with initialization process. Value forwarded to event handler.
    void TermControl::_UpdateFont(const bool initialUpdate)
    {
        const int newDpi = static_cast<int>(static_cast<double>(USER_DEFAULT_SCREEN_DPI) * SwapChainPanel().CompositionScaleX());

        // TODO: MSFT:20895307 If the font doesn't exist, this doesn't
        //      actually fail. We need a way to gracefully fallback.
        _renderer->TriggerFontChange(newDpi, _desiredFont, _actualFont);

        // If the actual font isn't what was requested...
        if (_actualFont.GetFaceName() != _desiredFont.GetFaceName())
        {