Repository: microsoft/terminal
File: src/terminal/input/terminalInput.cpp (C++)

Code before:
            return false;
        }

        return HandleFocus(focusEvent.GetFocus());
    }

    // On key presses, prepare to translate to VT compatible sequences
    if (pInEvent->EventType() != InputEventType::KeyEvent)
    {
        return false;
    }

    auto keyEvent = *static_cast<const KeyEvent* const>(pInEvent);

    // GH#4999 - If we're in win32-input mode, skip straight to doing that.
    // Since this mode handles all types of key events, do nothing else.
    // Only do this if win32-input-mode support isn't manually disabled.
    if (_inputMode.test(Mode::Win32) && !_forceDisableWin32InputMode)
    {
        const auto seq = _GenerateWin32KeySequence(keyEvent);
        _SendInputSequence(seq);
        return true;
    }

    // Check if this key matches the last recorded key code.
    const auto matchingLastKeyPress = _lastVirtualKeyCode && _lastVirtualKeyCode.value() == keyEvent.GetVirtualKeyCode();

    // Only need to handle key down. See raw key handler (see RawReadWaitRoutine in stream.cpp)
    if (!keyEvent.IsKeyDown())
    {
        // If this is a release of the last recorded key press, we can reset that.
        if (matchingLastKeyPress)
        {
            _lastVirtualKeyCode = std::nullopt;
        }
        return false;
    }

    // If this is a repeat of the last recorded key press, and Auto Repeat Mode
    // is disabled, then we should suppress this event.
    if (matchingLastKeyPress && !_inputMode.test(Mode::AutoRepeat))
    {
        // Note that we must return true here to say we've handled the event,
        // otherwise the key press can still end up being submitted.
        return true;
    }
    _lastVirtualKeyCode = keyEvent.GetVirtualKeyCode();

    // The VK_BACK key depends on the state of Backarrow Key mode (DECBKM).
    // If the mode is set, we should send BS. If reset, we should send DEL.
    if (keyEvent.GetVirtualKeyCode() == VK_BACK)

Review comment (suggestion):
cute `std::optional` trick: you don't need to check whether the optional is populated before doing a comparison; `nullopt == T{}` will always return `false`

Code after:
            return false;
        }

        return HandleFocus(focusEvent.GetFocus());
    }

    // On key presses, prepare to translate to VT compatible sequences
    if (pInEvent->EventType() != InputEventType::KeyEvent)
    {
        return false;
    }

    auto keyEvent = *static_cast<const KeyEvent* const>(pInEvent);

    // GH#4999 - If we're in win32-input mode, skip straight to doing that.
    // Since this mode handles all types of key events, do nothing else.
    // Only do this if win32-input-mode support isn't manually disabled.
    if (_inputMode.test(Mode::Win32) && !_forceDisableWin32InputMode)
    {
        const auto seq = _GenerateWin32KeySequence(keyEvent);
        _SendInputSequence(seq);
        return true;
    }

    // Check if this key matches the last recorded key code.
    const auto matchingLastKeyPress = _lastVirtualKeyCode == keyEvent.GetVirtualKeyCode();

    // Only need to handle key down. See raw key handler (see RawReadWaitRoutine in stream.cpp)
    if (!keyEvent.IsKeyDown())
    {
        // If this is a release of the last recorded key press, we can reset that.
        if (matchingLastKeyPress)
        {
            _lastVirtualKeyCode = std::nullopt;
        }
        return false;
    }

    // If this is a repeat of the last recorded key press, and Auto Repeat Mode
    // is disabled, then we should suppress this event.
    if (matchingLastKeyPress && !_inputMode.test(Mode::AutoRepeat))
    {
        // Note that we must return true here to say we've handled the event,
        // otherwise the key press can still end up being submitted.
        return true;
    }
    _lastVirtualKeyCode = keyEvent.GetVirtualKeyCode();

    // The VK_BACK key depends on the state of Backarrow Key mode (DECBKM).
    // If the mode is set, we should send BS. If reset, we should send DEL.
    if (keyEvent.GetVirtualKeyCode() == VK_BACK)