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

Code before:
    switch (eraseType)
    {
    case DispatchTypes::EraseType::FromBeginning:
        _FillRect(textBuffer, { 0, row, col + 1, row + 1 }, L' ', eraseAttributes);
        return true;
    case DispatchTypes::EraseType::ToEnd:
        _FillRect(textBuffer, { col, row, textBuffer.GetLineWidth(row), row + 1 }, L' ', eraseAttributes);
        return true;
    case DispatchTypes::EraseType::All:
        _FillRect(textBuffer, { 0, row, textBuffer.GetLineWidth(row), row + 1 }, L' ', eraseAttributes);
        return true;
    default:
        return false;
    }
}

// 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:

Review comment (suggestion):
You could just write `if (eraseRect)` here. The `operator bool` does exactly this, plus it ensures that all coordinates are >= 0, which seems to me like something we might want in this code.

Code after:
    switch (eraseType)
    {
    case DispatchTypes::EraseType::FromBeginning:
        _FillRect(textBuffer, { 0, row, col + 1, row + 1 }, L' ', eraseAttributes);
        return true;
    case DispatchTypes::EraseType::ToEnd:
        _FillRect(textBuffer, { col, row, textBuffer.GetLineWidth(row), row + 1 }, L' ', eraseAttributes);
        return true;
    case DispatchTypes::EraseType::All:
        _FillRect(textBuffer, { 0, row, textBuffer.GetLineWidth(row), row + 1 }, L' ', eraseAttributes);
        return true;
    default:
        return false;
    }
}

// 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: