From 3f7af7bfb8749a7bc9a63b8159a5e7614e93acfc Mon Sep 17 00:00:00 2001 From: Sylvie Crowe <107814465+oneirocosm@users.noreply.github.com> Date: Tue, 1 Oct 2024 11:54:39 -0700 Subject: [PATCH] fix: modifier keys on windows and linux (#922) --- .gitattributes | 2 +- frontend/app/view/term/term.tsx | 6 +++--- frontend/util/keyutil.ts | 28 ++++++++++++++++++++++++---- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/.gitattributes b/.gitattributes index fbd75d33c..07764a78d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -* text=lf \ No newline at end of file +* text eol=lf \ No newline at end of file diff --git a/frontend/app/view/term/term.tsx b/frontend/app/view/term/term.tsx index d99dbe96b..3484d6126 100644 --- a/frontend/app/view/term/term.tsx +++ b/frontend/app/view/term/term.tsx @@ -314,9 +314,9 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => { return false; } if (PLATFORM == "win32" || PLATFORM == "linux") { - const reservedAltKeys = ["Alt:t", "Alt:n", "Alt:w", "Alt:m", "Alt:g", "Alt:[", "Alt:]", "Alt:Shift:r"]; - for (let i = 0; i < reservedAltKeys.length; i++) { - if (keyutil.checkKeyPressed(waveEvent, reservedAltKeys[i])) { + const reservedCmdKeys = ["Cmd:t", "Cmd:n", "Cmd:w", "Cmd:m", "Cmd:g", "Cmd:[", "Cmd:]", "Cmd:Shift:r"]; + for (let i = 0; i < reservedCmdKeys.length; i++) { + if (keyutil.checkKeyPressed(waveEvent, reservedCmdKeys[i])) { return false; } } diff --git a/frontend/util/keyutil.ts b/frontend/util/keyutil.ts index 253a35451..b1fb5ccdf 100644 --- a/frontend/util/keyutil.ts +++ b/frontend/util/keyutil.ts @@ -47,16 +47,36 @@ function parseKeyDescription(keyDescription: string): KeyPressDecl { let keys = keyDescription.replace(/[()]/g, "").split(":"); for (let key of keys) { if (key == "Cmd") { + if (PLATFORM == PlatformMacOS) { + rtn.mods.Meta = true; + } else { + rtn.mods.Alt = true; + } rtn.mods.Cmd = true; } else if (key == "Shift") { rtn.mods.Shift = true; } else if (key == "Ctrl") { rtn.mods.Ctrl = true; } else if (key == "Option") { + if (PLATFORM == PlatformMacOS) { + rtn.mods.Alt = true; + } else { + rtn.mods.Meta = true; + } rtn.mods.Option = true; } else if (key == "Alt") { + if (PLATFORM == PlatformMacOS) { + rtn.mods.Option = true; + } else { + rtn.mods.Cmd = true; + } rtn.mods.Alt = true; } else if (key == "Meta") { + if (PLATFORM == PlatformMacOS) { + rtn.mods.Cmd = true; + } else { + rtn.mods.Option = true; + } rtn.mods.Meta = true; } else { let { key: parsedKey, type: keyType } = parseKey(key); @@ -138,10 +158,10 @@ function isInputEvent(event: WaveKeyboardEvent): boolean { function checkKeyPressed(event: WaveKeyboardEvent, keyDescription: string): boolean { let keyPress = parseKeyDescription(keyDescription); - if (!keyPress.mods.Alt && notMod(keyPress.mods.Option, event.option)) { + if (notMod(keyPress.mods.Option, event.option)) { return false; } - if (!keyPress.mods.Meta && notMod(keyPress.mods.Cmd, event.cmd)) { + if (notMod(keyPress.mods.Cmd, event.cmd)) { return false; } if (notMod(keyPress.mods.Shift, event.shift)) { @@ -150,10 +170,10 @@ function checkKeyPressed(event: WaveKeyboardEvent, keyDescription: string): bool if (notMod(keyPress.mods.Ctrl, event.control)) { return false; } - if (keyPress.mods.Alt && !event.alt) { + if (notMod(keyPress.mods.Alt, event.alt)) { return false; } - if (keyPress.mods.Meta && !event.meta) { + if (notMod(keyPress.mods.Meta, event.meta)) { return false; } let eventKey = "";