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

Code before:

        {
            e.Handled(true);
            return;
        }

        // GH#2235: Terminal::Settings hasn't been modified to differentiate
        // between AltGr and Ctrl+Alt yet.
        // -> Don't check for key bindings if this is an AltGr key combination.
        //
        // GH#4999: Only process keybindings on the keydown. If we don't check
        // this at all, we'll process the keybinding twice. If we only process
        // keybindings on the keyUp, then we'll still send the keydown to the
        // connected terminal application, and something like ctrl+shift+T will
        // emit a ^T to the pipe.
        if (!modifiers.IsAltGrPressed() && keyDown && _TryHandleKeyBinding(vkey, scanCode, modifiers))
        {
            e.Handled(true);
            return;
        }

        if (vkey == VK_SPACE && modifiers.IsAltPressed())
        {
            if (const auto bindings = _settings.KeyBindings())
            {
                if (!bindings.IsKeyChordExplicitlyUnbound({ modifiers.IsCtrlPressed(), modifiers.IsAltPressed(), modifiers.IsShiftPressed(), modifiers.IsWinPressed(), vkey, 0 }))
                {
                    // If we get here, it means that
                    //      1. we do not have a command bound to alt+space
                    //      2. alt+space was not explicitly unbound
                    // That means that XAML handled the alt+space to open up the context menu, and
                    // so we don't want to send anything to the terminal
                    e.Handled(true);
                    return;
                }
            }
        }

        if (_TrySendKeyEvent(vkey, scanCode, modifiers, keyDown))
        {
            e.Handled(true);
            return;
        }

        // Manually prevent keyboard navigation with tab. We want to send tab to
        // the terminal, and we don't want to be able to escape focus of the
        // control with tab.
        e.Handled(e.OriginalKey() == VirtualKey::Tab);
    }

    // Method Description:

Review comment (suggestion):
Similarly to `_TryHandleKeyBinding` you should pass the scanCode here if you can.

Code after:

        {
            e.Handled(true);
            return;
        }

        // GH#2235: Terminal::Settings hasn't been modified to differentiate
        // between AltGr and Ctrl+Alt yet.
        // -> Don't check for key bindings if this is an AltGr key combination.
        //
        // GH#4999: Only process keybindings on the keydown. If we don't check
        // this at all, we'll process the keybinding twice. If we only process
        // keybindings on the keyUp, then we'll still send the keydown to the
        // connected terminal application, and something like ctrl+shift+T will
        // emit a ^T to the pipe.
        if (!modifiers.IsAltGrPressed() && keyDown && _TryHandleKeyBinding(vkey, scanCode, modifiers))
        {
            e.Handled(true);
            return;
        }

        if (vkey == VK_SPACE && modifiers.IsAltPressed())
        {
            if (const auto bindings = _settings.KeyBindings())
            {
                if (!bindings.IsKeyChordExplicitlyUnbound({ modifiers.IsCtrlPressed(), modifiers.IsAltPressed(), modifiers.IsShiftPressed(), modifiers.IsWinPressed(), vkey, scanCode }))
                {
                    // If we get here, it means that
                    //      1. we do not have a command bound to alt+space
                    //      2. alt+space was not explicitly unbound
                    // That means that XAML handled the alt+space to open up the context menu, and
                    // so we don't want to send anything to the terminal
                    // TODO GH#11018: Add a new "openSystemMenu" keybinding
                    e.Handled(true);
                    return;
                }
            }
        }

        if (_TrySendKeyEvent(vkey, scanCode, modifiers, keyDown))
        {
            e.Handled(true);
            return;
        }

        // Manually prevent keyboard navigation with tab. We want to send tab to
        // the terminal, and we don't want to be able to escape focus of the
        // control with tab.
        e.Handled(e.OriginalKey() == VirtualKey::Tab);
    }