Skip to content

Commit dfa716a

Browse files
authored
fix(test): restart not working in long tests (@Leonabcd123) (monkeytypegame#7143)
### Description Fixed a bug where you can't use shift + quick restart key to restart long tests. I didn't touch the enter one because it seemed to use a different logic (double tapping shift + enter) and I'm not sure why it does.
1 parent 032844d commit dfa716a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

frontend/src/ts/event-handlers/global.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { focusWords } from "../test/test-ui";
1010
import * as TestLogic from "../test/test-logic";
1111
import { navigate } from "../controllers/route-controller";
1212
import { isInputElementFocused } from "../input/input-element";
13+
import * as ManualRestart from "../test/manual-restart-tracker";
1314

1415
document.addEventListener("keydown", (e) => {
1516
if (PageTransition.get()) return;
@@ -74,6 +75,9 @@ document.addEventListener("keydown", (e) => {
7475
) {
7576
e.preventDefault();
7677
if (ActivePage.get() === "test") {
78+
if (e.shiftKey) {
79+
ManualRestart.set();
80+
}
7781
TestLogic.restart();
7882
} else {
7983
void navigate("");

frontend/src/ts/input/handlers/keydown.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as Notifications from "../../elements/notifications";
1111
import * as KeyConverter from "../../utils/key-converter";
1212
import * as ShiftTracker from "../../test/shift-tracker";
1313
import * as CompositionState from "../../states/composition";
14+
import * as ManualRestart from "../../test/manual-restart-tracker";
1415
import { canQuickRestart } from "../../utils/quick-restart";
1516
import * as CustomText from "../../test/custom-text";
1617
import * as CustomTextState from "../../states/custom-text-name";
@@ -28,6 +29,9 @@ export async function handleTab(e: KeyboardEvent, now: number): Promise<void> {
2829
if (Config.quickRestart === "tab") {
2930
e.preventDefault();
3031
if ((TestWords.hasTab && e.shiftKey) || !TestWords.hasTab) {
32+
if (e.shiftKey) {
33+
ManualRestart.set();
34+
}
3135
TestLogic.restart();
3236
return;
3337
}
@@ -81,6 +85,9 @@ export async function handleEnter(
8185
if (Config.quickRestart === "enter") {
8286
e.preventDefault();
8387
if ((TestWords.hasNewline && e.shiftKey) || !TestWords.hasNewline) {
88+
if (e.shiftKey) {
89+
ManualRestart.set();
90+
}
8491
TestLogic.restart();
8592
return;
8693
}
@@ -206,6 +213,11 @@ export async function onKeydown(event: KeyboardEvent): Promise<void> {
206213

207214
if (event.key === "Escape" && Config.quickRestart === "esc") {
208215
event.preventDefault();
216+
217+
if (event.shiftKey) {
218+
ManualRestart.set();
219+
}
220+
209221
TestLogic.restart();
210222
return;
211223
}

0 commit comments

Comments
 (0)