Skip to content

Commit 926b369

Browse files
byseif21fehmer
andauthored
fix(commandline): missing initialize input validation handler for commandOverride (@byseif21) (monkeytypegame#6788)
### Description commands opened directly via `commandOverride` (e.g., `changeCustomPolyglot` when triggered by a text button after a page refresh) were not correctly initializing their input validation handlers. --------- Co-authored-by: Christian Fehmer <[email protected]> Co-authored-by: Christian Fehmer <[email protected]>
1 parent a9a9994 commit 926b369

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

frontend/src/ts/commandline/commandline.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export function show(
163163
value: showInputCommand.defaultValue?.() ?? "",
164164
icon: showInputCommand.icon ?? "fa-chevron-right",
165165
};
166+
createValidationHandler(showInputCommand);
166167
void updateInput(inputModeParams.value as string);
167168
hideCommands();
168169
}
@@ -627,17 +628,7 @@ async function runActiveCommand(): Promise<void> {
627628
value: command.defaultValue?.() ?? "",
628629
icon: command.icon ?? "fa-chevron-right",
629630
};
630-
if ("validation" in command && !handlersCache.has(command.id)) {
631-
const commandWithValidation = command as CommandWithValidation<unknown>;
632-
const handler = createInputEventHandler(
633-
updateValidationResult,
634-
commandWithValidation.validation,
635-
"inputValueConvert" in commandWithValidation
636-
? commandWithValidation.inputValueConvert
637-
: undefined
638-
);
639-
handlersCache.set(command.id, handler);
640-
}
631+
createValidationHandler(command);
641632

642633
await updateInput(inputModeParams.value as string);
643634
hideCommands();
@@ -814,6 +805,20 @@ function updateValidationResult(
814805
*/
815806
const handlersCache = new Map<string, (e: Event) => Promise<void>>();
816807

808+
function createValidationHandler(command: Command): void {
809+
if ("validation" in command && !handlersCache.has(command.id)) {
810+
const commandWithValidation = command as CommandWithValidation<unknown>;
811+
const handler = createInputEventHandler(
812+
updateValidationResult,
813+
commandWithValidation.validation,
814+
"inputValueConvert" in commandWithValidation
815+
? commandWithValidation.inputValueConvert
816+
: undefined
817+
);
818+
handlersCache.set(command.id, handler);
819+
}
820+
}
821+
817822
const modal = new AnimatedModal({
818823
dialogId: "commandLine",
819824
customEscapeHandler: (): void => {

frontend/src/ts/commandline/lists.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,21 @@ export const commands: CommandsSubgroup = {
106106
...ResultSavingCommands,
107107

108108
//behavior
109-
difficultyCommand,
110-
buildCommandForConfigKey("quickRestart"),
111-
buildCommandForConfigKey("repeatQuotes"),
112-
blindModeCommand,
113-
buildCommandForConfigKey("alwaysShowWordsHistory"),
114-
buildCommandForConfigKey("singleListCommandLine"),
115-
minSpeedCommand,
116-
minAccCommand,
117-
...MinBurstCommands,
118-
buildCommandForConfigKey("britishEnglish"),
119-
...FunboxCommands,
120-
buildCommandForConfigKey("customLayoutfluid"),
121-
buildCommandForConfigKey("customPolyglot"),
109+
...buildCommands(
110+
difficultyCommand,
111+
"quickRestart",
112+
"repeatQuotes",
113+
blindModeCommand,
114+
"alwaysShowWordsHistory",
115+
"singleListCommandLine",
116+
minSpeedCommand,
117+
minAccCommand,
118+
...MinBurstCommands,
119+
"britishEnglish",
120+
...FunboxCommands,
121+
"customLayoutfluid",
122+
"customPolyglot"
123+
),
122124

123125
//input
124126
...buildCommands(

frontend/src/ts/elements/modes-notice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export async function update(): Promise<void> {
115115
.join(", ");
116116

117117
$(".pageTest #testModesNotice").append(
118-
`<button class="textButton" commandId="changeCustomPolyglot"><i class="fas fa-globe-americas"></i>${languages}</button>`
118+
`<button class="textButton" commandId="setCustomPolyglotCustom"><i class="fas fa-globe-americas"></i>${languages}</button>`
119119
);
120120
}
121121

0 commit comments

Comments
 (0)