Skip to content

Commit

Permalink
platform: filter out right-sided modifiers returned by TKey when norm…
Browse files Browse the repository at this point in the history
…alizing keys
  • Loading branch information
magiblot committed Oct 23, 2024
1 parent f07e275 commit 68c474b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions source/platform/termio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,15 @@ void TermIO::keyModsOff(ConsoleCtl &con) noexcept

void TermIO::normalizeKey(KeyDownEvent &keyDown) noexcept
{
TKey key(keyDown);
if (key.mods & (kbShift | kbCtrlShift | kbLeftAlt))
TKey tKey(keyDown);
ushort newMods = tKey.mods & (kbShift | kbLeftCtrl | kbLeftAlt);
if (newMods != 0)
{
// Modifier precedece: Shift < Ctrl < Alt.
int largestMod = (key.mods & kbLeftAlt) ? 2
: (key.mods & kbCtrlShift) ? 1
int largestMod = (newMods & kbLeftAlt) ? 2
: (newMods & kbLeftShift) ? 1
: 0;
if (ushort keyCode = moddedKeyCodes[key.code][largestMod])
if (ushort keyCode = moddedKeyCodes[tKey.code][largestMod])
{
keyDown.keyCode = keyCode;
if (keyDown.charScan.charCode < ' ')
Expand All @@ -350,9 +351,9 @@ void TermIO::normalizeKey(KeyDownEvent &keyDown) noexcept
// when available.
ushort origMods = keyDown.controlKeyState;
keyDown.controlKeyState =
((origMods | key.mods) & ~(kbCtrlShift | kbAltShift))
| ((origMods & kbCtrlShift ? origMods : key.mods) & kbCtrlShift)
| ((origMods & kbAltShift ? origMods : key.mods) & kbAltShift)
((origMods | newMods) & ~(kbCtrlShift | kbAltShift))
| ((origMods & kbCtrlShift ? origMods : newMods) & kbCtrlShift)
| ((origMods & kbAltShift ? origMods : newMods) & kbAltShift)
;
}

Expand Down

0 comments on commit 68c474b

Please sign in to comment.