Skip to content

Commit

Permalink
I thought this might fix the problems I noticed in #4354, but I don't…
Browse files Browse the repository at this point in the history
… think that's the case after all. Gonna step back and try again.
  • Loading branch information
zadjii-msft committed Jan 27, 2020
1 parent 2d07816 commit 41eeda1
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 27 deletions.
34 changes: 34 additions & 0 deletions src/buffer/out/textBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<short> 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++)
{
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -1656,6 +1670,7 @@ HRESULT TextBuffer::Reflow(TextBuffer& oldBuffer, TextBuffer& newBuffer)
if (iOldRow < cOldRowsTotal - 1)
{
hr = newBuffer.NewlineCursor() ? hr : E_OUTOFMEMORY;
// manuallyNewlined = true;
}
else
{
Expand Down Expand Up @@ -1689,11 +1704,20 @@ HRESULT TextBuffer::Reflow(TextBuffer& oldBuffer, TextBuffer& newBuffer)
if (newBuffer.GetRowByOffset(gsl::narrow_cast<size_t>(coordNewCursor.Y) - 1).GetCharRow().WasWrapForced())
{
hr = newBuffer.NewlineCursor() ? hr : E_OUTOFMEMORY;
// manuallyNewlined = true;
}
}
}
}
}

// if (SUCCEEDED(hr))
// {
// if (manuallyNewlined && charRow.WasWrapForced() && !firstWrapChangedRow)
// {

// }
// }
}
if (SUCCEEDED(hr))
{
Expand Down Expand Up @@ -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();

Expand Down
54 changes: 27 additions & 27 deletions src/host/screenInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
}
Expand Down

0 comments on commit 41eeda1

Please sign in to comment.