From 41eeda1b4e6e2a0bc40f8640f3fe4c2ff7c6bca1 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Mon, 27 Jan 2020 16:26:54 -0600 Subject: [PATCH] I thought this might fix the problems I noticed in #4354, but I don't think that's the case after all. Gonna step back and try again. --- src/buffer/out/textBuffer.cpp | 34 ++++++++++++++++++++++ src/host/screenInfo.cpp | 54 +++++++++++++++++------------------ 2 files changed, 61 insertions(+), 27 deletions(-) diff --git a/src/buffer/out/textBuffer.cpp b/src/buffer/out/textBuffer.cpp index 99cdbc78e54..16ec34f0911 100644 --- a/src/buffer/out/textBuffer.cpp +++ b/src/buffer/out/textBuffer.cpp @@ -1572,11 +1572,15 @@ HRESULT TextBuffer::Reflow(TextBuffer& oldBuffer, TextBuffer& newBuffer) short const cOldRowsTotal = cOldLastChar.Y + 1; short const cOldColsTotal = oldBuffer.GetSize().Width(); + short const newCols = newBuffer.GetSize().Width(); COORD cNewCursorPos = { 0 }; bool fFoundCursorPos = false; HRESULT hr = S_OK; + + std::optional firstWrapChangedRow{ std::nullopt }; + // Loop through all the rows of the old buffer and reprint them into the new buffer for (short iOldRow = 0; iOldRow < cOldRowsTotal; iOldRow++) { @@ -1609,6 +1613,13 @@ HRESULT TextBuffer::Reflow(TextBuffer& oldBuffer, TextBuffer& newBuffer) } } + if (!firstWrapChangedRow.has_value() && + ((iRight > newCols) || + charRow.WasWrapForced())) + { + firstWrapChangedRow = newCursor.GetPosition().Y; + } + // Loop through every character in the current row (up to // the "right" boundary, which is one past the final valid // character) @@ -1635,6 +1646,9 @@ HRESULT TextBuffer::Reflow(TextBuffer& oldBuffer, TextBuffer& newBuffer) } CATCH_RETURN(); } + + // bool manuallyNewlined = false; + if (SUCCEEDED(hr)) { // If we didn't have a full row to copy, insert a new @@ -1656,6 +1670,7 @@ HRESULT TextBuffer::Reflow(TextBuffer& oldBuffer, TextBuffer& newBuffer) if (iOldRow < cOldRowsTotal - 1) { hr = newBuffer.NewlineCursor() ? hr : E_OUTOFMEMORY; + // manuallyNewlined = true; } else { @@ -1689,11 +1704,20 @@ HRESULT TextBuffer::Reflow(TextBuffer& oldBuffer, TextBuffer& newBuffer) if (newBuffer.GetRowByOffset(gsl::narrow_cast(coordNewCursor.Y) - 1).GetCharRow().WasWrapForced()) { hr = newBuffer.NewlineCursor() ? hr : E_OUTOFMEMORY; + // manuallyNewlined = true; } } } } } + + // if (SUCCEEDED(hr)) + // { + // if (manuallyNewlined && charRow.WasWrapForced() && !firstWrapChangedRow) + // { + + // } + // } } if (SUCCEEDED(hr)) { @@ -1762,6 +1786,16 @@ HRESULT TextBuffer::Reflow(TextBuffer& oldBuffer, TextBuffer& newBuffer) newCursor.SetSize(ulSize); } + if (SUCCEEDED(hr) && firstWrapChangedRow.has_value()) + { + const short invalidTop = firstWrapChangedRow.value(); + const COORD newLastChar = newBuffer.GetLastNonSpaceCharacter(); + const short newRowsTotal = newLastChar.Y + 1; + + newBuffer._renderTarget.TriggerRedraw( + Viewport::FromInclusive({ 0, invalidTop, newCols, newRowsTotal })); + } + newCursor.EndDeferDrawing(); oldCursor.EndDeferDrawing(); diff --git a/src/host/screenInfo.cpp b/src/host/screenInfo.cpp index 0471c2bda07..53a6c54a0c6 100644 --- a/src/host/screenInfo.cpp +++ b/src/host/screenInfo.cpp @@ -1425,8 +1425,8 @@ bool SCREEN_INFORMATION::IsMaximizedY() const // Save cursor's relative height versus the viewport short cursorHeightInViewportBefore = _textBuffer->GetCursor().GetPosition().Y - _viewport.Top(); - auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation(); - const bool isConpty = gci.IsInVtIoMode(); + // auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation(); + // const bool isConpty = gci.IsInVtIoMode(); HRESULT hr = TextBuffer::Reflow(*_textBuffer.get(), *newTextBuffer.get()); const bool widthChanged = coordNewScreenSize.X != _textBuffer->GetSize().Width(); @@ -1442,31 +1442,31 @@ bool SCREEN_INFORMATION::IsMaximizedY() const _textBuffer.swap(newTextBuffer); } - // GH#3490 - In conpty mode, We want to invalidate all of the viewport that - // might have been below any wrapped lines, up until the last character of - // the buffer. Lines that were wrapped may have been re-wrapped during this - // resize, so we want them repainted to the terminal. We don't want to just - // invalidate everything though - if there were blank lines at the bottom, - // those can just be ignored. - if (isConpty && widthChanged) - { - // Loop through all the rows of the old buffer and reprint them into the new buffer - const auto bottom = std::max(_textBuffer->GetCursor().GetPosition().Y, - std::min(_viewport.BottomInclusive(), - _textBuffer->GetLastNonSpaceCharacter().Y)); - bool foundWrappedLine = false; - for (short y = _viewport.Top(); y <= bottom; y++) - { - // Fetch the row and its "right" which is the last printable character. - const ROW& row = _textBuffer->GetRowByOffset(y); - const CharRow& charRow = row.GetCharRow(); - if (foundWrappedLine || charRow.WasWrapForced()) - { - foundWrappedLine = true; - _renderTarget.TriggerRedraw(Viewport::FromDimensions({ 0, y }, _viewport.Width(), 1)); - } - } - } + // // GH#3490 - In conpty mode, We want to invalidate all of the viewport that + // // might have been below any wrapped lines, up until the last character of + // // the buffer. Lines that were wrapped may have been re-wrapped during this + // // resize, so we want them repainted to the terminal. We don't want to just + // // invalidate everything though - if there were blank lines at the bottom, + // // those can just be ignored. + // if (isConpty && widthChanged) + // { + // // Loop through all the rows of the old buffer and reprint them into the new buffer + // const auto bottom = std::max(_textBuffer->GetCursor().GetPosition().Y, + // std::min(_viewport.BottomInclusive(), + // _textBuffer->GetLastNonSpaceCharacter().Y)); + // bool foundWrappedLine = false; + // for (short y = _viewport.Top(); y <= bottom; y++) + // { + // // Fetch the row and its "right" which is the last printable character. + // const ROW& row = _textBuffer->GetRowByOffset(y); + // const CharRow& charRow = row.GetCharRow(); + // if (foundWrappedLine || charRow.WasWrapForced()) + // { + // foundWrappedLine = true; + // _renderTarget.TriggerRedraw(Viewport::FromDimensions({ 0, y }, _viewport.Width(), 1)); + // } + // } + // } return NTSTATUS_FROM_HRESULT(hr); }