Repository: microsoft/terminal
File: src/cascadia/TerminalCore/Terminal.cpp (C++)

Code before:
        vkey = _VirtualKeyFromScanCode(scanCode);
    }
    if (vkey == 0)
    {
        vkey = _VirtualKeyFromCharacter(ch);
    }

    // GH#1527: When the user has auto mark prompts enabled, we're going to try
    // and heuristically detect if this was the line the prompt was on.
    // * If the key was an Enter keypress (Terminal.app also marks ^C keypresses
    //   as prompts. That's omitted for now.)
    // * AND we're not in the alt buffer
    //
    // Then treat this line like it's a prompt mark.
    if (_autoMarkPrompts && vkey == VK_RETURN && !_inAltBuffer())
    {
        // * If we have a _currentPrompt:
        //   - Then we did know that the prompt started, (we may have also
        //     already gotten a CommandStart sequence). The user has pressed
        //     enter, and we're treating that like the prompt has now ended.
        //     - Perform a FTCS_COMMAND_EXECUTED, so that we start marking this
        //       as output.
        //     - This enables CMD to have full FTCS support, even though there's
        //       no point in CMD to insert a "preexec" hook
        // * Else: We don't have a prompt. We don't know anything else, but we
        //   can set the whole like as the prompt, no command, and start the
        //   command_executed now.

        if (_currentPrompt)
        {
            OutputStart();
        }
        else
        {
            DispatchTypes::ScrollMark mark;
            mark.category = DispatchTypes::MarkCategory::Prompt;
            // Don't set the color - we'll automatically use the DEFAULT_FOREGROUND
            // color for any MarkCategory::Prompt marks without one set.
            AddMark(mark);
            _currentPrompt = &_scrollMarks.back();
            OutputStart();
        }
    }

    // Unfortunately, the UI doesn't give us both a character down and a
    // character up event, only a character received event. So fake sending both
    // to the terminal input translator. Unless it's in win32-input-mode, it'll
    // ignore the keyup.
    KeyEvent keyDown{ true, 1, vkey, scanCode, ch, states.Value() };
    KeyEvent keyUp{ false, 1, vkey, scanCode, ch, states.Value() };
    const auto handledDown = _terminalInput->HandleKey(&keyDown);

Review comment (suggestion):
```suggestion
        //   can set the whole line as the prompt, no command, and start the
```

Code after:
        //   - Then we did know that the prompt started, (we may have also
        //     already gotten a MarkCommandStart sequence). The user has pressed
        //     enter, and we're treating that like the prompt has now ended.
        //     - Perform a FTCS_COMMAND_EXECUTED, so that we start marking this
        //       as output.
        //     - This enables CMD to have full FTCS support, even though there's
        //       no point in CMD to insert a "pre exec" hook
        // * Else: We don't have a prompt. We don't know anything else, but we
        //   can set the whole line as the prompt, no command, and start the
        //   command_executed now.
        //
        // Fortunately, MarkOutputStart will do all this logic for us!
        MarkOutputStart();
    }

    // Unfortunately, the UI doesn't give us both a character down and a
    // character up event, only a character received event. So fake sending both
    // to the terminal input translator. Unless it's in win32-input-mode, it'll
    // ignore the keyup.
    const KeyEvent keyDown{ true, 1, vkey, scanCode, ch, states.Value() };
    const KeyEvent keyUp{ false, 1, vkey, scanCode, ch, states.Value() };
    const auto handledDown = _terminalInput->HandleKey(&keyDown);
    const auto handledUp = _terminalInput->HandleKey(&keyUp);
    return handledDown || handledUp;
}

// Method Description:
// - Tell the terminal input that we gained or lost focus. If the client
//   requested focus events, this will send a message to them.
// - ConPTY ALWAYS wants focus events.
// Arguments:
// - focused: true if we're focused, false otherwise.
// Return Value:
// - none
void Terminal::FocusChanged(const bool focused) noexcept
{
    _terminalInput->HandleFocus(focused);
}

// Method Description:
// - Invalidates the regions described in the given pattern tree for the rendering purposes
// Arguments:
// - The interval tree containing regions that need to be invalidated
void Terminal::_InvalidatePatternTree(const interval_tree::IntervalTree<til::point, size_t>& tree)
{
    const auto vis = _VisibleStartIndex();
    auto invalidate = [=](const PointTree::interval& interval) {
        const til::point startCoord{ interval.start.x, interval.start.y + vis };
        const til::point endCoord{ interval.stop.x, interval.stop.y + vis };
        _InvalidateFromCoords(startCoord, endCoord);
    };