Skip to content

Commit da535a6

Browse files
authored
refactor: use dom utils in caret code (@Miodec) (monkeytypegame#7218)
Also adds a few more utils
1 parent 67a34e0 commit da535a6

File tree

4 files changed

+159
-112
lines changed

4 files changed

+159
-112
lines changed

frontend/src/ts/test/caret.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as TestState from "../test/test-state";
44
import { subscribe } from "../observables/config-event";
55
import { Caret } from "../utils/caret";
66
import * as CompositionState from "../states/composition";
7+
import { qsr } from "../utils/dom";
78

89
export function stopAnimation(): void {
910
caret.stopBlinking();
@@ -40,10 +41,7 @@ export function updatePosition(noAnim = false): void {
4041
});
4142
}
4243

43-
export const caret = new Caret(
44-
document.getElementById("caret") as HTMLElement,
45-
Config.caretStyle,
46-
);
44+
export const caret = new Caret(qsr("#caret"), Config.caretStyle);
4745

4846
subscribe((eventKey) => {
4947
if (eventKey === "caretStyle") {

frontend/src/ts/test/pace-caret.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as TestState from "./test-state";
66
import * as ConfigEvent from "../observables/config-event";
77
import { getActiveFunboxes } from "./funbox/list";
88
import { Caret } from "../utils/caret";
9+
import { qsr } from "../utils/dom";
910

1011
type Settings = {
1112
wpm: number;
@@ -22,10 +23,7 @@ let startTimestamp = 0;
2223

2324
export let settings: Settings | null = null;
2425

25-
export const caret = new Caret(
26-
document.getElementById("paceCaret") as HTMLElement,
27-
Config.paceCaretStyle,
28-
);
26+
export const caret = new Caret(qsr("#paceCaret"), Config.paceCaretStyle);
2927

3028
let lastTestWpm = 0;
3129

0 commit comments

Comments
 (0)