Repository: microsoft/terminal
File: src/cascadia/PublicTerminalCore/HwndTerminalAutomationPeer.cpp (C++)

Code before:
// - <none>
// Return Value:
// - <none>
void HwndTerminalAutomationPeer::SignalTextChanged()
{
    UiaTracing::Signal::TextChanged();
    LOG_IF_FAILED(UiaRaiseAutomationEvent(this, UIA_Text_TextChangedEventId));
}

// Method Description:
// - Signals the ui automation client that the cursor's state has changed and should be updated
// Arguments:
// - <none>
// Return Value:
// - <none>
void HwndTerminalAutomationPeer::SignalCursorChanged()
{
    UiaTracing::Signal::CursorChanged();
    LOG_IF_FAILED(UiaRaiseAutomationEvent(this, UIA_Text_TextSelectionChangedEventId));
}

void HwndTerminalAutomationPeer::NotifyNewOutput(std::wstring_view newOutput)
{
    if (_notificationsUnavailable) [[unlikely]]
    {
        // We failed to delay-load the notification function, so let's just skip the whole thing.
        return;
    }

    // Try to suppress any events (or event data)
    // that is just the keypress the user made
    auto sanitized{ Sanitize(newOutput) };
    while (!_keyEvents.empty() && IsReadable(sanitized))
    {
        if (til::toupper_ascii(sanitized.front()) == _keyEvents.front())
        {
            // the key event's character (i.e. the "A" key) matches
            // the output character (i.e. "a" or "A" text).
            // We can assume that the output character resulted from
            // the pressed key, so we can ignore it.
            sanitized = sanitized.substr(1);
            _keyEvents.pop_front();
        }
        else
        {
            // The output doesn't match,
            // so clear the input stack and
            // move on to fire the event.
            _keyEvents.clear();
            break;
        }

Review comment (suggestion):
```suggestion
        // What if you tried to notify, but God said no
```

f it ship it

Code after:
// - <none>
// Return Value:
// - <none>
void HwndTerminalAutomationPeer::SignalTextChanged()
{
    UiaTracing::Signal::TextChanged();
    LOG_IF_FAILED(UiaRaiseAutomationEvent(this, UIA_Text_TextChangedEventId));
}

// Method Description:
// - Signals the ui automation client that the cursor's state has changed and should be updated
// Arguments:
// - <none>
// Return Value:
// - <none>
void HwndTerminalAutomationPeer::SignalCursorChanged()
{
    UiaTracing::Signal::CursorChanged();
    LOG_IF_FAILED(UiaRaiseAutomationEvent(this, UIA_Text_TextSelectionChangedEventId));
}

void HwndTerminalAutomationPeer::NotifyNewOutput(std::wstring_view newOutput)
{
    if (_notificationsUnavailable) [[unlikely]]
    {
        // What if you tried to notify, but God said no
        return;
    }

    // Try to suppress any events (or event data)
    // that is just the keypress the user made
    auto sanitized{ Sanitize(newOutput) };
    while (!_keyEvents.empty() && IsReadable(sanitized))
    {
        if (til::toupper_ascii(sanitized.front()) == _keyEvents.front())
        {
            // the key event's character (i.e. the "A" key) matches
            // the output character (i.e. "a" or "A" text).
            // We can assume that the output character resulted from
            // the pressed key, so we can ignore it.
            sanitized = sanitized.substr(1);
            _keyEvents.pop_front();
        }
        else
        {
            // The output doesn't match,
            // so clear the input stack and
            // move on to fire the event.
            _keyEvents.clear();
            break;
        }