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

Code before:
// - True.
bool AdaptDispatch::DeleteCharacter(const VTInt count)
{
    _InsertDeleteCharacterHelper(-count);
    return true;
}

// Routine Description:
// - ECH - Erase Characters from the current cursor position, by replacing
//     them with a space. This will only erase characters in the current line,
//     and won't wrap to the next. The attributes of any erased positions
//     receive the currently selected attributes.
// Arguments:
// - numChars - The number of characters to erase.
// Return Value:
// - True.
bool AdaptDispatch::EraseCharacters(const VTInt numChars)
{
    auto& textBuffer = _api.GetTextBuffer();
    const auto row = textBuffer.GetCursor().GetPosition().y;
    const auto startCol = textBuffer.GetCursor().GetPosition().x;
    const auto endCol = std::min<VTInt>(startCol + numChars, textBuffer.GetLineWidth(row));

    // The ECH control is expected to reset the delayed wrap flag.
    textBuffer.GetCursor().ResetDelayEOLWrap();

    const auto eraseAttributes = _GetEraseAttributes(textBuffer);
    textBuffer.FillRect({ startCol, row, endCol, row + 1 }, whitespace, eraseAttributes);

    return true;
}

// Routine Description:
// - ED - Erases a portion of the current viewable area (viewport) of the console.
// 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
//      The scrollback (outside the viewport area)
// Return Value:
// - True if handled successfully. False otherwise.
bool AdaptDispatch::EraseInDisplay(const DispatchTypes::EraseType eraseType)
{
    RETURN_BOOL_IF_FALSE(eraseType <= DispatchTypes::EraseType::Scrollback);

    // First things first. If this is a "Scrollback" clear, then just do that.
    // Scrollback clears erase everything in the "scrollback" of a *nix terminal
    //      Everything that's scrolled off the screen so far.
    // Or if it's an Erase All, then we also need to handle that specially
    //      by moving the current contents of the viewport into the scrollback.

Review comment (suggestion):
We don't appear to be triggering the `NotifyAccessibilityChange` event now. I believe this is needed for ConHost's accessibility support. 

Code after:
// - True.
bool AdaptDispatch::DeleteCharacter(const VTInt count)
{
    _InsertDeleteCharacterHelper(-count);
    return true;
}

// Routine Description:
// - Fills an area of the buffer with a given character and attributes.
// Arguments:
// - textBuffer - Target buffer to be filled.
// - fillRect - Area of the buffer that will be affected.
// - fillChar - Character to be written to the buffer.
// - fillAttrs - Attributes to be written to the buffer.
// Return Value:
// - <none>
void AdaptDispatch::_FillRect(TextBuffer& textBuffer, const til::rect& fillRect, const std::wstring_view& fillChar, const TextAttribute& fillAttrs) const
{
    textBuffer.FillRect(fillRect, fillChar, fillAttrs);
    _api.NotifyAccessibilityChange(fillRect);
}

// Routine Description:
// - ECH - Erase Characters from the current cursor position, by replacing
//     them with a space. This will only erase characters in the current line,
//     and won't wrap to the next. The attributes of any erased positions
//     receive the currently selected attributes.
// Arguments:
// - numChars - The number of characters to erase.
// Return Value:
// - True.
bool AdaptDispatch::EraseCharacters(const VTInt numChars)
{
    auto& textBuffer = _api.GetTextBuffer();
    const auto row = textBuffer.GetCursor().GetPosition().y;
    const auto startCol = textBuffer.GetCursor().GetPosition().x;
    const auto endCol = std::min<VTInt>(startCol + numChars, textBuffer.GetLineWidth(row));

    // The ECH control is expected to reset the delayed wrap flag.
    textBuffer.GetCursor().ResetDelayEOLWrap();

    const auto eraseAttributes = _GetEraseAttributes(textBuffer);
    _FillRect(textBuffer, { startCol, row, endCol, row + 1 }, whitespace, eraseAttributes);

    return true;
}

// Routine Description:
// - ED - Erases a portion of the current viewable area (viewport) of the console.
// Arguments:
// - eraseType - Determines whether to erase: