Skip to content

Commit 4dd8755

Browse files
Miodecfehmer
andauthored
refactor(commandline): rework commandline to use metadata approach (@Miodec, @fehmer) (monkeytypegame#6779)
Brr --------- Co-authored-by: Christian Fehmer <[email protected]>
1 parent f2b34a5 commit 4dd8755

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+2325
-3955
lines changed

frontend/__tests__/commandline/util.spec.ts

Lines changed: 417 additions & 0 deletions
Large diffs are not rendered by default.

frontend/__tests__/root/config.spec.ts

Lines changed: 538 additions & 190 deletions
Large diffs are not rendered by default.

frontend/src/ts/commandline/commandline-metadata.ts

Lines changed: 734 additions & 0 deletions
Large diffs are not rendered by default.

frontend/src/ts/commandline/commandline.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import * as ActivePage from "../states/active-page";
1111
import { focusWords } from "../test/test-ui";
1212
import * as Loader from "../elements/loader";
1313
import { Command, CommandsSubgroup, CommandWithValidation } from "./types";
14-
import { areSortedArraysEqual } from "../utils/arrays";
14+
import { areSortedArraysEqual, areUnsortedArraysEqual } from "../utils/arrays";
1515
import { parseIntOptional } from "../utils/numbers";
1616
import { debounce } from "throttle-debounce";
17+
import { intersect } from "@monkeytype/util/arrays";
1718
import { createInputEventHandler } from "../elements/input-validation";
1819

1920
type CommandlineMode = "search" | "input";
@@ -420,9 +421,16 @@ async function showCommands(): Promise<void> {
420421
const configKey = command.configKey ?? subgroup.configKey;
421422
if (configKey !== undefined) {
422423
if (command.configValueMode === "include") {
423-
isActive = (Config[configKey] as unknown[]).includes(
424-
command.configValue
425-
);
424+
if (Array.isArray(command.configValue)) {
425+
isActive = areUnsortedArraysEqual(
426+
intersect(Config[configKey] as unknown[], command.configValue),
427+
command.configValue
428+
);
429+
} else {
430+
isActive = (Config[configKey] as unknown[]).includes(
431+
command.configValue
432+
);
433+
}
426434
} else {
427435
isActive = Config[configKey] === command.configValue;
428436
}
@@ -506,7 +514,7 @@ async function showCommands(): Promise<void> {
506514
</div>
507515
</div>`;
508516
}
509-
if (command.id.startsWith("changeFont")) {
517+
if (command.id.startsWith("setFontFamily")) {
510518
let fontFamily = command.customData["name"];
511519

512520
if (fontFamily === "Helvetica") {

0 commit comments

Comments
 (0)