Skip to content

Commit 3f7af7b

Browse files
authored
fix: modifier keys on windows and linux (#922)
1 parent 538d4be commit 3f7af7b

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* text=lf
1+
* text eol=lf

frontend/app/view/term/term.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,9 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
314314
return false;
315315
}
316316
if (PLATFORM == "win32" || PLATFORM == "linux") {
317-
const reservedAltKeys = ["Alt:t", "Alt:n", "Alt:w", "Alt:m", "Alt:g", "Alt:[", "Alt:]", "Alt:Shift:r"];
318-
for (let i = 0; i < reservedAltKeys.length; i++) {
319-
if (keyutil.checkKeyPressed(waveEvent, reservedAltKeys[i])) {
317+
const reservedCmdKeys = ["Cmd:t", "Cmd:n", "Cmd:w", "Cmd:m", "Cmd:g", "Cmd:[", "Cmd:]", "Cmd:Shift:r"];
318+
for (let i = 0; i < reservedCmdKeys.length; i++) {
319+
if (keyutil.checkKeyPressed(waveEvent, reservedCmdKeys[i])) {
320320
return false;
321321
}
322322
}

frontend/util/keyutil.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,36 @@ function parseKeyDescription(keyDescription: string): KeyPressDecl {
4747
let keys = keyDescription.replace(/[()]/g, "").split(":");
4848
for (let key of keys) {
4949
if (key == "Cmd") {
50+
if (PLATFORM == PlatformMacOS) {
51+
rtn.mods.Meta = true;
52+
} else {
53+
rtn.mods.Alt = true;
54+
}
5055
rtn.mods.Cmd = true;
5156
} else if (key == "Shift") {
5257
rtn.mods.Shift = true;
5358
} else if (key == "Ctrl") {
5459
rtn.mods.Ctrl = true;
5560
} else if (key == "Option") {
61+
if (PLATFORM == PlatformMacOS) {
62+
rtn.mods.Alt = true;
63+
} else {
64+
rtn.mods.Meta = true;
65+
}
5666
rtn.mods.Option = true;
5767
} else if (key == "Alt") {
68+
if (PLATFORM == PlatformMacOS) {
69+
rtn.mods.Option = true;
70+
} else {
71+
rtn.mods.Cmd = true;
72+
}
5873
rtn.mods.Alt = true;
5974
} else if (key == "Meta") {
75+
if (PLATFORM == PlatformMacOS) {
76+
rtn.mods.Cmd = true;
77+
} else {
78+
rtn.mods.Option = true;
79+
}
6080
rtn.mods.Meta = true;
6181
} else {
6282
let { key: parsedKey, type: keyType } = parseKey(key);
@@ -138,10 +158,10 @@ function isInputEvent(event: WaveKeyboardEvent): boolean {
138158

139159
function checkKeyPressed(event: WaveKeyboardEvent, keyDescription: string): boolean {
140160
let keyPress = parseKeyDescription(keyDescription);
141-
if (!keyPress.mods.Alt && notMod(keyPress.mods.Option, event.option)) {
161+
if (notMod(keyPress.mods.Option, event.option)) {
142162
return false;
143163
}
144-
if (!keyPress.mods.Meta && notMod(keyPress.mods.Cmd, event.cmd)) {
164+
if (notMod(keyPress.mods.Cmd, event.cmd)) {
145165
return false;
146166
}
147167
if (notMod(keyPress.mods.Shift, event.shift)) {
@@ -150,10 +170,10 @@ function checkKeyPressed(event: WaveKeyboardEvent, keyDescription: string): bool
150170
if (notMod(keyPress.mods.Ctrl, event.control)) {
151171
return false;
152172
}
153-
if (keyPress.mods.Alt && !event.alt) {
173+
if (notMod(keyPress.mods.Alt, event.alt)) {
154174
return false;
155175
}
156-
if (keyPress.mods.Meta && !event.meta) {
176+
if (notMod(keyPress.mods.Meta, event.meta)) {
157177
return false;
158178
}
159179
let eventKey = "";

0 commit comments

Comments
 (0)