Skip to content

Commit 4d835ed

Browse files
authored
fix(manual-restart): can't restart in long tests (@Leonabcd123, @fehmer) (#7775)
### Steps to reproduce 1. Set quick restart to `tab` (doesn't have to be that, just as an example) 2. Start long test 3. Try to restart by pressing `Shift+Tab` 4. Notice that it doesn't work Fixes tooltips as well.
1 parent 1be6f5a commit 4d835ed

3 files changed

Lines changed: 45 additions & 6 deletions

File tree

frontend/src/ts/input/hotkeys/quickrestart.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import { isAnyPopupVisible } from "../../utils/misc";
33
import { navigate } from "../../controllers/route-controller";
44
import { restartTestEvent } from "../../events/test";
55
import { getActivePage } from "../../states/core";
6-
import { hotkeys } from "../../states/hotkeys";
6+
import { hotkeys, quickRestartHotkeyMap } from "../../states/hotkeys";
77
import { createHotkey } from "./utils";
8+
import { getConfig } from "../../config/store";
9+
import { isLongTest } from "../../states/test";
810

911
function quickRestart(e: KeyboardEvent): void {
1012
if (isAnyPopupVisible()) {
@@ -20,4 +22,20 @@ function quickRestart(e: KeyboardEvent): void {
2022
}
2123
}
2224

23-
createHotkey(() => hotkeys.quickRestart, quickRestart);
25+
// Disable restart when we're in long test and quick restart key is enter, because `shift + enter, shift +
26+
// enter` is already reserved for bail out keybind.
27+
createHotkey(
28+
() => hotkeys.quickRestart,
29+
quickRestart,
30+
() => ({ enabled: !isLongTest() || getConfig.quickRestart !== "enter" }),
31+
);
32+
33+
// We also want to have a hotkey for quick restart key without shift, so when the
34+
// test is considered long (which means that we can't quick restart), we show a
35+
// notification when the user tries to press the quick restart key without shift,
36+
// and we'll restart when it's pressed with shift.
37+
createHotkey(
38+
() => quickRestartHotkeyMap[getConfig.quickRestart],
39+
quickRestart,
40+
() => ({ enabled: isLongTest() }),
41+
);

frontend/src/ts/states/hotkeys.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { Hotkey } from "@tanstack/solid-hotkeys";
33
import { createEffect } from "solid-js";
44
import { createStore } from "solid-js/store";
55
import { getConfig } from "../config/store";
6-
import { wordsHaveNewline, wordsHaveTab } from "./test";
6+
import { wordsHaveNewline, wordsHaveTab, isLongTest } from "./test";
77
import { getActivePage } from "./core";
88
import { NoKey } from "../input/hotkeys/utils";
99

10-
const quickRestartHotkeyMap: Record<QuickRestart, Hotkey> = {
10+
export const quickRestartHotkeyMap: Record<QuickRestart, Hotkey> = {
1111
off: NoKey,
1212
esc: "Escape",
1313
tab: "Tab",
@@ -31,7 +31,7 @@ function updateHotkeys(): Hotkeys {
3131
return {
3232
quickRestart: shiftHotkey(
3333
quickRestartHotkeyMap[getConfig.quickRestart],
34-
isOnTestPage && wordsHaveTab(),
34+
isOnTestPage && (wordsHaveTab() || isLongTest()),
3535
),
3636
commandline: shiftHotkey(
3737
getConfig.quickRestart === "esc" ? "Tab" : "Escape",
@@ -44,6 +44,7 @@ function shiftHotkey(hotkey: Hotkey, shift: boolean): Hotkey {
4444
if (shift) {
4545
if (hotkey === "Tab") return "Shift+Tab";
4646
if (hotkey === "Enter") return "Shift+Enter";
47+
if (hotkey === "Escape") return "Shift+Escape";
4748
}
4849
return hotkey;
4950
}

frontend/src/ts/states/test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import { createSignal } from "solid-js";
1+
import { createSignal, createEffect } from "solid-js";
22
import { Challenge } from "@monkeytype/schemas/challenges";
3+
import { getConfig } from "../config/store";
4+
import { getActivePage } from "./core";
5+
import { canQuickRestart } from "../utils/quick-restart";
6+
import { getData as getCustomTextData } from "../test/custom-text";
7+
import { isCustomTextLong } from "../legacy-states/custom-text-name";
38

49
export const [wordsHaveNewline, setWordsHaveNewline] = createSignal(false);
510
export const [wordsHaveTab, setWordsHaveTab] = createSignal(false);
@@ -8,3 +13,18 @@ export const [getLoadedChallenge, setLoadedChallenge] =
813
createSignal<Challenge | null>(null);
914
export const [getResultVisible, setResultVisible] = createSignal(false);
1015
export const [getFocus, setFocus] = createSignal(false);
16+
17+
export const [isLongTest, setIsLongTest] = createSignal(false);
18+
19+
createEffect(() => {
20+
getActivePage(); // depend on active page
21+
setIsLongTest(
22+
!canQuickRestart(
23+
getConfig.mode,
24+
getConfig.words,
25+
getConfig.time,
26+
getCustomTextData(),
27+
isCustomTextLong() ?? false,
28+
),
29+
);
30+
});

0 commit comments

Comments
 (0)