Skip to content

Commit

Permalink
fix(layout emulator): automatically typing special characters when ca…
Browse files Browse the repository at this point in the history
…ps lock is enabled

actually closes #4743 this time
  • Loading branch information
Miodec committed Oct 30, 2023
1 parent 05fc903 commit dffbeda
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion frontend/src/ts/test/layout-emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,37 @@ import * as Misc from "../utils/misc";
import { capsState } from "./caps-warning";
import * as Notifications from "../elements/notifications";

function shouldCapslockUseSecondCharLocation(keyLocation: string): boolean {
return [
"KeyQ",
"KeyW",
"KeyE",
"KeyR",
"KeyT",
"KeyY",
"KeyU",
"KeyI",
"KeyO",
"KeyP",
"KeyA",
"KeyS",
"KeyD",
"KeyF",
"KeyG",
"KeyH",
"KeyJ",
"KeyK",
"KeyL",
"KeyZ",
"KeyX",
"KeyC",
"KeyV",
"KeyB",
"KeyN",
"KeyM",
].includes(keyLocation);
}

export async function getCharFromEvent(
event: JQuery.KeyDownEvent
): Promise<string | null> {
Expand Down Expand Up @@ -197,8 +228,14 @@ export async function getCharFromEvent(
return null;
}
}

const capsSwap = shouldCapslockUseSecondCharLocation(event.code);
const charIndex =
(capsState && !event.shiftKey) || (!capsState && event.shiftKey) ? 1 : 0;
(capsState && !event.shiftKey && capsSwap) ||
(capsState && event.shiftKey && !capsSwap) ||
(!capsState && event.shiftKey)
? 1
: 0;
const char = layoutMap[mapIndex][charIndex];
if (char) {
return char;
Expand Down

0 comments on commit dffbeda

Please sign in to comment.