Skip to content

Commit

Permalink
Handle Ctrl+Space as a special case.
Browse files Browse the repository at this point in the history
  • Loading branch information
j4james committed Feb 1, 2024
1 parent c669afe commit 432785d
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/terminal/input/terminalInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,12 @@ TerminalInput::OutputType TerminalInput::HandleKey(const INPUT_RECORD& event)
return keyMatch->second;
}

// If it's not in the key map, we'll use the UnicodeChar, if provided.
if (unicodeChar != 0)
// If it's not in the key map, we'll use the UnicodeChar, if provided,
// except in the case of Ctrl+Space, which is often mapped incorrectly as
// a space character when it's expected to be mapped to NUL. We need to
// let that fall through to the standard mapping algorithm below.
const auto ctrlSpaceKey = ctrlIsReallyPressed && virtualKeyCode == VK_SPACE;
if (unicodeChar != 0 && !ctrlSpaceKey)
{
// In the case of an AltGr key, we may still need to apply a Ctrl
// modifier to the char, either because both Ctrl keys were pressed,
Expand Down Expand Up @@ -389,13 +393,6 @@ try
defineKeyWithAltModifier(Ctrl + Enhanced + VK_RETURN, L"\n"s);
defineKeyWithAltModifier(Ctrl + Shift + Enhanced + VK_RETURN, L"\n"s);

// SPACE maps to SP, and Ctrl+SPACE to NUL. The Shift modifier as no effect.
// The Alt modifier adds an ESC prefix (not standard).
defineKeyWithAltModifier(VK_SPACE, L" "s);
defineKeyWithAltModifier(Shift + VK_SPACE, L" "s);
defineKeyWithAltModifier(Ctrl + VK_SPACE, L"\0"s);
defineKeyWithAltModifier(Ctrl + Shift + VK_SPACE, L"\0"s);

if (_inputMode.test(Mode::Ansi))
{
// F1 to F4 map to the VT keypad function keys, which are SS3 sequences.
Expand Down Expand Up @@ -581,6 +578,10 @@ wchar_t TerminalInput::_makeCtrlChar(const wchar_t ch)
{
return ch & 0b11111;
}
if (ch == L' ')
{
return 0x00;
}
if (ch == L'/')
{
return 0x1F;
Expand Down

0 comments on commit 432785d

Please sign in to comment.