Repository: microsoft/terminal
File: src/terminal/adapter/adaptDispatch.cpp (C++)

Code before:
// Routine Description:
// - Selectively erases unprotected cells in an area of the buffer.
// Arguments:
// - textBuffer - Target buffer to be erased.
// - eraseRect - Area of the buffer that will be affected.
// Return Value:
// - <none>
void AdaptDispatch::_SelectiveEraseRect(TextBuffer& textBuffer, const til::rect& eraseRect)
{
    if (eraseRect.left < eraseRect.right && eraseRect.top < eraseRect.bottom)
    {
        for (auto row = eraseRect.top; row < eraseRect.bottom; row++)
        {
            auto& rowBuffer = textBuffer.GetRowByOffset(row);
            const auto& attrs = rowBuffer.GetAttrRow();
            auto& chars = rowBuffer.GetCharRow();
            for (auto col = eraseRect.left; col < eraseRect.right; col++)
            {
                // Only unprotected cells are affected.
                if (!attrs.GetAttrByColumn(col).IsProtected())
                {
                    // The text is cleared but the attributes are left as is.
                    chars.ClearGlyph(col);
                    textBuffer.TriggerRedraw(Viewport::FromCoord({ col, row }));
                }
            }
        }
        _api.NotifyAccessibilityChange(eraseRect);
    }
}

// Routine Description:
// - DECSED - Selectively erases unprotected cells in a portion of the viewport.
// Arguments:
// - eraseType - Determines whether to erase:
//      From beginning (top-left corner) to the cursor
//      From cursor to end (bottom-right corner)
//      The entire viewport area
// Return Value:
// - True if handled successfully. False otherwise.
bool AdaptDispatch::SelectiveEraseInDisplay(const DispatchTypes::EraseType eraseType)
{
    const auto viewport = _api.GetViewport();
    auto& textBuffer = _api.GetTextBuffer();
    const auto bufferWidth = textBuffer.GetSize().Width();
    const auto row = textBuffer.GetCursor().GetPosition().Y;
    const auto col = textBuffer.GetCursor().GetPosition().X;

    switch (eraseType)
    {
    case DispatchTypes::EraseType::FromBeginning:

Review comment (suggestion):
I realise this bit will likely have to be rewritten somewhat to work with the new `ROW` implementation in PR #13626, so I'm happy to wait for that to merge first.

Code after:
// Routine Description:
// - Selectively erases unprotected cells in an area of the buffer.
// Arguments:
// - textBuffer - Target buffer to be erased.
// - eraseRect - Area of the buffer that will be affected.
// Return Value:
// - <none>
void AdaptDispatch::_SelectiveEraseRect(TextBuffer& textBuffer, const til::rect& eraseRect)
{
    if (eraseRect)
    {
        for (auto row = eraseRect.top; row < eraseRect.bottom; row++)
        {
            auto& rowBuffer = textBuffer.GetRowByOffset(row);
            const auto& attrs = rowBuffer.GetAttrRow();
            auto& chars = rowBuffer.GetCharRow();
            for (auto col = eraseRect.left; col < eraseRect.right; col++)
            {
                // Only unprotected cells are affected.
                if (!attrs.GetAttrByColumn(col).IsProtected())
                {
                    // The text is cleared but the attributes are left as is.
                    chars.ClearGlyph(col);
                    textBuffer.TriggerRedraw(Viewport::FromCoord({ col, row }));
                }
            }
        }
        _api.NotifyAccessibilityChange(eraseRect);
    }
}

// Routine Description:
// - DECSED - Selectively erases unprotected cells in a portion of the viewport.
// Arguments:
// - eraseType - Determines whether to erase:
//      From beginning (top-left corner) to the cursor
//      From cursor to end (bottom-right corner)
//      The entire viewport area
// Return Value:
// - True if handled successfully. False otherwise.
bool AdaptDispatch::SelectiveEraseInDisplay(const DispatchTypes::EraseType eraseType)
{
    const auto viewport = _api.GetViewport();
    auto& textBuffer = _api.GetTextBuffer();
    const auto bufferWidth = textBuffer.GetSize().Width();
    const auto row = textBuffer.GetCursor().GetPosition().Y;
    const auto col = textBuffer.GetCursor().GetPosition().X;

    switch (eraseType)
    {
    case DispatchTypes::EraseType::FromBeginning: