Repository: microsoft/terminal
File: src/cascadia/TerminalControl/ControlCore.cpp (C++)

Code before:
    // - Makes the cursor briefly visible during typing.
    // Arguments:
    // - vkey: The vkey of the key pressed.
    // - scanCode: The scan code of the key pressed.
    // - modifiers: The Microsoft::Terminal::Core::ControlKeyStates representing the modifier key states.
    // - keyDown: If true, the key was pressed, otherwise the key was released.
    bool ControlCore::TrySendKeyEvent(const WORD vkey,
                                      const WORD scanCode,
                                      const ControlKeyStates modifiers,
                                      const bool keyDown)
    {
        // Update the selection, if it's present
        // GH#6423 - don't dismiss selection if the key that was pressed was a
        // modifier key. We'll wait for a real keystroke to dismiss the
        // GH #7395 - don't dismiss selection when taking PrintScreen
        // selection.
        // GH#8522, GH#3758 - Only modify the selection on key _down_. If we
        // modify on key up, then there's chance that we'll immediately dismiss
        // a selection created by an action bound to a keydown.
        if (HasSelection() &&
            !KeyEvent::IsModifierKey(vkey) &&
            vkey != VK_SNAPSHOT &&
            keyDown)
        {
            if (_terminal->IsInMarkMode() && modifiers.IsCtrlPressed() && vkey == 'A')
            {
                auto lock = _terminal->LockForWriting();
                _terminal->SelectAll();
                _updateSelection();
                return true;
            }

            // try to update the selection
            if (const auto updateSlnParams{ _terminal->ConvertKeyEventToUpdateSelectionParams(modifiers, vkey) })
            {
                auto lock = _terminal->LockForWriting();
                _terminal->UpdateSelection(updateSlnParams->first, updateSlnParams->second, modifiers);
                _updateSelection();
                return true;
            }

            // GH#8791 - don't dismiss selection if Windows key was also pressed as a key-combination.
            if (!modifiers.IsWinPressed())
            {
                _terminal->ClearSelection();
                _updateSelection();
            }

            // When there is a selection active, escape should clear it and NOT flow through
            // to the terminal. With any other keypress, it should clear the selection AND
            // flow through to the terminal.

Review comment (suggestion):
The namespace qualifier seems overly specific. FYI this should work as expected from other languages:
```cpp
using ::Microsoft::Terminal::Core::Terminal::SelectionInteractionMode;
```

Code after:
    // - Makes the cursor briefly visible during typing.
    // Arguments:
    // - vkey: The vkey of the key pressed.
    // - scanCode: The scan code of the key pressed.
    // - modifiers: The Microsoft::Terminal::Core::ControlKeyStates representing the modifier key states.
    // - keyDown: If true, the key was pressed, otherwise the key was released.
    bool ControlCore::TrySendKeyEvent(const WORD vkey,
                                      const WORD scanCode,
                                      const ControlKeyStates modifiers,
                                      const bool keyDown)
    {
        // Update the selection, if it's present
        // GH#6423 - don't dismiss selection if the key that was pressed was a
        // modifier key. We'll wait for a real keystroke to dismiss the
        // GH #7395 - don't dismiss selection when taking PrintScreen
        // selection.
        // GH#8522, GH#3758 - Only modify the selection on key _down_. If we
        // modify on key up, then there's chance that we'll immediately dismiss
        // a selection created by an action bound to a keydown.
        if (HasSelection() &&
            !KeyEvent::IsModifierKey(vkey) &&
            vkey != VK_SNAPSHOT &&
            keyDown)
        {
            const auto isInMarkMode = _terminal->SelectionMode() == ::Microsoft::Terminal::Core::Terminal::SelectionInteractionMode::Mark;
            if (isInMarkMode && modifiers.IsCtrlPressed() && vkey == 'A')
            {
                auto lock = _terminal->LockForWriting();
                _terminal->SelectAll();
                _updateSelectionUI();
                return true;
            }

            // try to update the selection
            if (const auto updateSlnParams{ _terminal->ConvertKeyEventToUpdateSelectionParams(modifiers, vkey) })
            {
                auto lock = _terminal->LockForWriting();
                _terminal->UpdateSelection(updateSlnParams->first, updateSlnParams->second, modifiers);
                _updateSelectionUI();
                return true;
            }

            // GH#8791 - don't dismiss selection if Windows key was also pressed as a key-combination.
            if (!modifiers.IsWinPressed())
            {
                _terminal->ClearSelection();
                _updateSelectionUI();
            }

            // When there is a selection active, escape should clear it and NOT flow through
            // to the terminal. With any other keypress, it should clear the selection AND