Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
832dd24
Fix caps warning inverted
Leonabcd123 Feb 6, 2026
24ea851
Change mac handling
Leonabcd123 Feb 6, 2026
5f3b184
keydown
Leonabcd123 Feb 6, 2026
012db8e
Visibility
Leonabcd123 Feb 6, 2026
32e454f
Caps check
Leonabcd123 Feb 6, 2026
998bc92
fehmer's implementation
Leonabcd123 Feb 6, 2026
c7a6335
Rename
Leonabcd123 Feb 6, 2026
eeaf210
Remove updateCapsLockVisibility from update
Leonabcd123 Feb 6, 2026
70d0f6a
Comments
Leonabcd123 Feb 6, 2026
c52510e
Refactor
Leonabcd123 Feb 7, 2026
d8318a5
Refactor
Leonabcd123 Feb 7, 2026
59791a4
Change comments
Leonabcd123 Feb 7, 2026
1c744fa
Refactor
Leonabcd123 Feb 7, 2026
54d4bac
Style
Leonabcd123 Feb 7, 2026
f1cfe91
Refactor
Leonabcd123 Feb 7, 2026
ad37cf4
Comment
Leonabcd123 Feb 7, 2026
f29ffd4
Factory
Leonabcd123 Feb 7, 2026
370bb82
Revert "Factory"
Leonabcd123 Feb 7, 2026
9e60760
Remove export for windows util
Leonabcd123 Feb 7, 2026
f305594
Remove exports for all os utils
Leonabcd123 Feb 7, 2026
7ea70ed
Capitalization
Leonabcd123 Feb 7, 2026
baabf8e
Comment
Leonabcd123 Feb 7, 2026
5e03fb9
Caps Lock style
Leonabcd123 Feb 7, 2026
f73769e
Mac
Leonabcd123 Feb 7, 2026
8acdb8e
Should still use isCapsLockOn
Leonabcd123 Feb 7, 2026
7d0f722
Change mac handling
Leonabcd123 Feb 7, 2026
764df08
Add Linux comment
Leonabcd123 Feb 7, 2026
9187d23
Remove getCurrentOs
Leonabcd123 Feb 7, 2026
0468c1c
Inline updateCapsKeyup and updateCapsKeydown
Leonabcd123 Feb 7, 2026
2a472ab
Add back getCurrentOs
Leonabcd123 Feb 7, 2026
5f44564
Hopefully fix mac
Leonabcd123 Feb 7, 2026
66bac51
Revert
Leonabcd123 Feb 7, 2026
744609c
Always false
Leonabcd123 Feb 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 34 additions & 13 deletions frontend/src/ts/test/caps-warning.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Config from "../config";
import * as Misc from "../utils/misc";
import { qsr } from "../utils/dom";
import { getCurrentOs } from "../utils/misc";

const el = qsr("#capsWarning");

export let capsState = false;
const os = getCurrentOs();

let visible = false;

Expand All @@ -22,16 +23,7 @@ function hide(): void {
}
}

function update(event: KeyboardEvent): void {
if (event.key === "CapsLock" && capsState !== null) {
capsState = !capsState;
} else {
const modState = event.getModifierState?.("CapsLock");
if (modState !== undefined) {
capsState = modState;
}
}

function updateCapsWarningVisibility(): void {
try {
if (Config.capsLockWarning && capsState) {
show();
Expand All @@ -41,8 +33,37 @@ function update(event: KeyboardEvent): void {
} catch {}
}

document.addEventListener("keyup", update);
function isCapsLockOn(event: KeyboardEvent): boolean {
return event.getModifierState("CapsLock");
}

document.addEventListener("keyup", (event) => {
if (os === "Mac") {
// macOS sends only keydown when enabling Caps Lock and only keyup when disabling.
if (event.key === "CapsLock") {
capsState = false;
}
} else if (os === "Windows") {
// Windows always sends the correct state on keyup (for Caps Lock and for regular keys)
capsState = isCapsLockOn(event);
} else if (event.key !== "CapsLock") {
// Linux sends the correct state on keyup if key isn't Caps Lock
capsState = isCapsLockOn(event);
}
updateCapsWarningVisibility();
});

document.addEventListener("keydown", (event) => {
if (Misc.isMac()) update(event);
if (os === "Mac") {
// macOS sends only keydown when enabling Caps Lock and only keyup when disabling.
capsState = isCapsLockOn(event);
updateCapsWarningVisibility();
} else if (os === "Linux") {
/* Linux sends the correct state before Caps Lock is toggled only on keydown,
* so we invert the modifier state
*/
if (event.key === "CapsLock") {
capsState = !isCapsLockOn(event);
}
}
});
21 changes: 19 additions & 2 deletions frontend/src/ts/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,14 +716,31 @@ function isPlatform(searchTerm: string | RegExp): boolean {
}
}

export function isLinux(): boolean {
function isWindows(): boolean {
return isPlatform("Win");
}

function isLinux(): boolean {
return isPlatform("Linux");
}

export function isMac(): boolean {
function isMac(): boolean {
return isPlatform("Mac");
}

export function getCurrentOs(): "Mac" | "Linux" | "Windows" | "Unknown" {
if (isMac()) {
return "Mac";
}
if (isLinux()) {
return "Linux";
}
if (isWindows()) {
return "Windows";
}
return "Unknown";
}

export function isMacLike(): boolean {
return isPlatform(/Mac|iPod|iPhone|iPad/);
}
Expand Down