Skip to content

Commit

Permalink
fix(layout emulator): shift + caps lock not working correctly sometim…
Browse files Browse the repository at this point in the history
…es when emulating a layout

closes #4743
  • Loading branch information
Miodec committed Oct 27, 2023
1 parent a30b367 commit 4d2a8f3
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions frontend/src/ts/test/layout-emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ import * as Notifications from "../elements/notifications";
export async function getCharFromEvent(
event: JQuery.KeyDownEvent
): Promise<string | null> {
function emulatedLayoutShouldShiftKey(
event: JQuery.KeyDownEvent,
newKeyPreview: string
): boolean {
if (capsState) return Misc.isASCIILetter(newKeyPreview) !== event.shiftKey;
return event.shiftKey;
}

let layout;

try {
Expand Down Expand Up @@ -205,9 +197,9 @@ export async function getCharFromEvent(
return null;
}
}
const newKeyPreview = layoutMap[mapIndex][0];
const shift = emulatedLayoutShouldShiftKey(event, newKeyPreview) ? 1 : 0;
const char = layoutMap[mapIndex][shift];
const charIndex =
(capsState && !event.shiftKey) || (!capsState && event.shiftKey) ? 1 : 0;
const char = layoutMap[mapIndex][charIndex];
if (char) {
return char;
} else {
Expand Down

0 comments on commit 4d2a8f3

Please sign in to comment.