mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-11-08 05:03:39 +08:00
impr(quick restart): add "enter" as an option to quick restart
This commit is contained in:
parent
b843cbec06
commit
78ecdcf91e
10 changed files with 84 additions and 6 deletions
|
|
@ -27,7 +27,7 @@ const CONFIG_SCHEMA = joi.object({
|
|||
showLiveWpm: joi.boolean(),
|
||||
showTimerProgress: joi.boolean(),
|
||||
smoothCaret: joi.string().valid("off", "slow", "medium", "fast"),
|
||||
quickRestart: joi.string().valid("off", "tab", "esc"),
|
||||
quickRestart: joi.string().valid("off", "tab", "esc", "enter"),
|
||||
punctuation: joi.boolean(),
|
||||
numbers: joi.boolean(),
|
||||
words: joi.number().min(0),
|
||||
|
|
|
|||
|
|
@ -4,6 +4,14 @@ const subgroup: MonkeyTypes.CommandsSubgroup = {
|
|||
title: "Quick restart...",
|
||||
configKey: "quickRestart",
|
||||
list: [
|
||||
{
|
||||
id: "changeQuickRestartEnter",
|
||||
display: "enter",
|
||||
configValue: "enter",
|
||||
exec: (): void => {
|
||||
UpdateConfig.setQuickRestartMode("enter");
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "changeQuickRestartTab",
|
||||
display: "tab",
|
||||
|
|
|
|||
|
|
@ -1196,11 +1196,13 @@ export function setSmoothLineScroll(mode: boolean, nosave?: boolean): boolean {
|
|||
|
||||
//quick restart
|
||||
export function setQuickRestartMode(
|
||||
mode: "off" | "esc" | "tab",
|
||||
mode: "off" | "esc" | "tab" | "enter",
|
||||
nosave?: boolean
|
||||
): boolean {
|
||||
if (
|
||||
!isConfigValueValid("quick restart mode", mode, [["off", "esc", "tab"]])
|
||||
!isConfigValueValid("quick restart mode", mode, [
|
||||
["off", "esc", "tab", "enter"],
|
||||
])
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -754,7 +754,7 @@ function handleTab(event: JQuery.KeyDownEvent, popupVisible: boolean): void {
|
|||
const modalVisible: boolean =
|
||||
Misc.isPopupVisible("commandLineWrapper") || popupVisible;
|
||||
|
||||
if (Config.quickRestart === "esc") {
|
||||
if (Config.quickRestart === "esc" || Config.quickRestart === "enter") {
|
||||
// dont do anything special
|
||||
if (modalVisible) return;
|
||||
|
||||
|
|
@ -899,6 +899,52 @@ $(document).on("keydown", async (event) => {
|
|||
});
|
||||
}
|
||||
|
||||
//enter
|
||||
if (event.key === "Enter" && Config.quickRestart === "enter") {
|
||||
const modalVisible: boolean =
|
||||
Misc.isPopupVisible("commandLineWrapper") || popupVisible;
|
||||
|
||||
if (modalVisible) return;
|
||||
|
||||
// change page if not on test page
|
||||
if (ActivePage.get() !== "test") {
|
||||
navigate("/");
|
||||
return;
|
||||
}
|
||||
|
||||
if (TestUI.resultVisible) {
|
||||
TestLogic.restart({
|
||||
event,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (Config.mode === "zen") {
|
||||
//do nothing
|
||||
} else if (
|
||||
!TestWords.hasNewline ||
|
||||
(TestWords.hasNewline && event.shiftKey)
|
||||
) {
|
||||
// in case we are in a long test, setting manual restart
|
||||
if (event.shiftKey) {
|
||||
ManualRestart.set();
|
||||
} else {
|
||||
ManualRestart.reset();
|
||||
}
|
||||
|
||||
//otherwise restart
|
||||
TestLogic.restart({
|
||||
event,
|
||||
});
|
||||
} else {
|
||||
handleChar("\n", TestInput.input.current.length);
|
||||
setWordsInput(" " + TestInput.input.current);
|
||||
if (Config.tapeMode !== "off") {
|
||||
TestUI.scrollTape();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!allowTyping) return;
|
||||
|
||||
if (!event.originalEvent?.isTrusted || TestUI.testRestarting) {
|
||||
|
|
|
|||
|
|
@ -57,6 +57,12 @@ export async function update(): Promise<void> {
|
|||
}
|
||||
}
|
||||
|
||||
if (TestWords.hasNewline && Config.quickRestart === "enter") {
|
||||
$(".pageTest #testModesNotice").append(
|
||||
`<div class="textButton noInteraction"><i class="fas fa-level-down-alt fa-rotate-90"></i>shift + enter to restart</div>`
|
||||
);
|
||||
}
|
||||
|
||||
const customTextName = CustomTextState.getCustomTextName();
|
||||
const isLong = CustomTextState.isCustomTextLong();
|
||||
if (Config.mode === "custom" && customTextName !== "" && isLong) {
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ $(document).ready(() => {
|
|||
CookiePopup.check();
|
||||
|
||||
$("body").css("transition", "background .25s, transform .05s");
|
||||
if (Config.quickRestart === "tab" || Config.quickRestart === "esc") {
|
||||
if (Config.quickRestart !== "off") {
|
||||
$("#restartTestButton").addClass("hidden");
|
||||
}
|
||||
if (!window.localStorage.getItem("merchbannerclosed")) {
|
||||
|
|
|
|||
|
|
@ -161,6 +161,8 @@ export function restart(options = {} as RestartOptions): void {
|
|||
message = "Press shift + tab or use your mouse to confirm.";
|
||||
} else if (Config.quickRestart === "esc") {
|
||||
message = "Press shift + escape or use your mouse to confirm.";
|
||||
} else if (Config.quickRestart === "enter") {
|
||||
message = "Press shift + enter or use your mouse to confirm.";
|
||||
}
|
||||
Notifications.add(
|
||||
`Quick restart disabled in long tests. ${message}`,
|
||||
|
|
@ -537,6 +539,7 @@ export async function init(): Promise<void> {
|
|||
|
||||
let hasTab = false;
|
||||
let hasNumbers = false;
|
||||
let hasNewline = false;
|
||||
|
||||
for (const word of generatedWords) {
|
||||
if (/\t/g.test(word) && !hasTab) {
|
||||
|
|
@ -545,10 +548,14 @@ export async function init(): Promise<void> {
|
|||
if (/\d/g.test(word) && !hasNumbers) {
|
||||
hasNumbers = true;
|
||||
}
|
||||
if (/\n/g.test(word) && !hasNewline) {
|
||||
hasNewline = true;
|
||||
}
|
||||
}
|
||||
|
||||
TestWords.setHasTab(hasTab);
|
||||
TestWords.setHasNumbers(hasNumbers);
|
||||
TestWords.setHasNewline(hasNewline);
|
||||
|
||||
if (beforeHasNumbers !== hasNumbers) {
|
||||
Keymap.refresh();
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ class Words {
|
|||
|
||||
export const words = new Words();
|
||||
export let hasTab = false;
|
||||
export let hasNewline = false;
|
||||
export let hasNumbers = false;
|
||||
export let randomQuote = null as unknown as MonkeyTypes.Quote;
|
||||
|
||||
|
|
@ -77,6 +78,10 @@ export function setHasTab(tf: boolean): void {
|
|||
hasTab = tf;
|
||||
}
|
||||
|
||||
export function setHasNewline(tf: boolean): void {
|
||||
hasNewline = tf;
|
||||
}
|
||||
|
||||
export function setHasNumbers(tf: boolean): void {
|
||||
hasNumbers = tf;
|
||||
}
|
||||
|
|
|
|||
2
frontend/src/ts/types/types.d.ts
vendored
2
frontend/src/ts/types/types.d.ts
vendored
|
|
@ -437,7 +437,7 @@ declare namespace MonkeyTypes {
|
|||
showLiveWpm: boolean;
|
||||
showTimerProgress: boolean;
|
||||
smoothCaret: SmoothCaretMode;
|
||||
quickRestart: "off" | "esc" | "tab";
|
||||
quickRestart: "off" | "esc" | "tab" | "enter";
|
||||
punctuation: boolean;
|
||||
numbers: boolean;
|
||||
words: WordsModes;
|
||||
|
|
|
|||
|
|
@ -32,6 +32,10 @@ function updateKeytips(): void {
|
|||
$("footer .keyTips").html(`
|
||||
<key>tab</key> - restart test<br>
|
||||
<key>esc</key> or <key>${modifierKey}</key>+<key>shift</key>+<key>p</key> - command line`);
|
||||
} else if (Config.quickRestart === "enter") {
|
||||
$("footer .keyTips").html(`
|
||||
<key>enter</key> - restart test<br>
|
||||
<key>esc</key> or <key>${modifierKey}</key>+<key>shift</key>+<key>p</key> - command line`);
|
||||
} else {
|
||||
$("footer .keyTips").html(`
|
||||
<key>tab</key> + <key>enter</key> - restart test<br>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue