Repository: microsoft/terminal
File: src/renderer/vt/state.cpp (C++)

Code before:
// Arguments:
// - iDpi - The Dots Per Inch to use for scaling. We will use this relative to
//      the system default DPI defined in Windows headers as a constant.
// Return Value:
// - HRESULT S_OK
[[nodiscard]] HRESULT VtEngine::UpdateDpi(const int /*iDpi*/) noexcept
{
    return S_OK;
}

// Method Description:
// - This method will update our internal reference for how big the viewport is.
//      If the viewport has changed size, then we'll need to send an update to
//      the terminal.
// Arguments:
// - srNewViewport - The bounds of the new viewport.
// Return Value:
// - HRESULT S_OK
[[nodiscard]] HRESULT VtEngine::UpdateViewport(const SMALL_RECT srNewViewport) noexcept
{
    auto hr = S_OK;
    const auto oldView = _lastViewport;
    const auto newView = Viewport::FromInclusive(srNewViewport);

    _lastViewport = newView;

    if ((oldView.Height() != newView.Height()) || (oldView.Width() != newView.Width()))
    {
        // Don't emit a resize event if we've requested it be suppressed
        if (!_suppressResizeRepaint)
        {
            hr = _ResizeWindow(newView.Width(), newView.Height());
        }
        _resized = true;
    }

    // See MSFT:19408543
    // Always clear the suppression request, even if the new size was the same
    //      as the last size. We're always going to get a UpdateViewport call
    //      for our first frame. However, we start with _suppressResizeRepaint set,
    //      to prevent that first UpdateViewport call from emitting our size.
    // If we only clear the flag when the new viewport is different, this can
    //      lead to the first _actual_ resize being suppressed.
    _suppressResizeRepaint = false;

    if (_resizeQuirk)
    {
        // GH#3490 - When the viewport width changed, don't do anything extra here.
        // If the buffer had areas that were invalid due to the resize, then the
        // buffer will have triggered it's own invalidations for what it knows is
        // invalid. Previously, we'd invalidate everything if the width changed,

Review comment (suggestion):
I was testing whether `VtEngine::UpdateViewport` works properly with the new, additional call to `UpdateViewport` on the first render cycle. It does, but it now called `InvalidateAll()` during the start, which I'm not sure is the correct thing to do.

These changes here fix the issue by moving the entire `if (_resizeQuirk)` block into the size check. Additionally I made a slight change to the code to move from comparing `Viewport`s to comparing `COORD`s, which simply the code.

Before:
```cpp
if ((oldView.Height() != newView.Height()) || (oldView.Width() != newView.Width()))
```

After:
```cpp
if (oldSize != newSize)
```

Code after:
// Arguments:
// - iDpi - The Dots Per Inch to use for scaling. We will use this relative to
//      the system default DPI defined in Windows headers as a constant.
// Return Value:
// - HRESULT S_OK
[[nodiscard]] HRESULT VtEngine::UpdateDpi(const int /*iDpi*/) noexcept
{
    return S_OK;
}

// Method Description:
// - This method will update our internal reference for how big the viewport is.
//      If the viewport has changed size, then we'll need to send an update to
//      the terminal.
// Arguments:
// - srNewViewport - The bounds of the new viewport.
// Return Value:
// - HRESULT S_OK
[[nodiscard]] HRESULT VtEngine::UpdateViewport(const SMALL_RECT srNewViewport) noexcept
{
    auto hr = S_OK;
    const auto newView = Viewport::FromInclusive(srNewViewport);
    const auto oldSize = _lastViewport.Dimensions();
    const auto newSize = newView.Dimensions();

    if (oldSize != newSize)
    {
        // Don't emit a resize event if we've requested it be suppressed
        if (!_suppressResizeRepaint)
        {
            hr = _ResizeWindow(newSize.X, newSize.Y);
        }

        if (_resizeQuirk)
        {
            // GH#3490 - When the viewport width changed, don't do anything extra here.
            // If the buffer had areas that were invalid due to the resize, then the
            // buffer will have triggered it's own invalidations for what it knows is
            // invalid. Previously, we'd invalidate everything if the width changed,
            // because we couldn't be sure if lines were reflowed.
            _invalidMap.resize(til::size{ newSize });
        }
        else
        {
            if (SUCCEEDED(hr))
            {
                _invalidMap.resize(til::size{ newSize }, true); // resize while filling in new space with repaint requests.

                // Viewport is smaller now - just update it all.
                if (oldSize.Y > newSize.Y || oldSize.X > newSize.X)
                {