Skip to content

Commit 3aeba30

Browse files
committed
fix(commandline): presets and tags not showing up in single list mode
fixed by calling beforelist when generating the single list this also means the list needs to be generated every time the commandline is opened because of that, list caching has been moved to the commandline module
1 parent c1b71fb commit 3aeba30

File tree

2 files changed

+15
-35
lines changed

2 files changed

+15
-35
lines changed

frontend/src/ts/commandline/commandline.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export function show(
6060
inputValue = "";
6161
activeIndex = 0;
6262
mode = "search";
63+
cachedSingleSubgroup = null;
6364
inputModeParams = {
6465
command: null,
6566
placeholder: null,
@@ -97,7 +98,6 @@ export function show(
9798
activeCommand = null;
9899
Focus.set(false);
99100
CommandlineLists.setStackToDefault();
100-
await beforeList();
101101
updateInput();
102102
await filterSubgroup();
103103
await showCommands();
@@ -247,13 +247,19 @@ function hideCommands(): void {
247247
element.innerHTML = "";
248248
}
249249

250+
let cachedSingleSubgroup: MonkeyTypes.CommandsSubgroup | null = null;
251+
250252
async function getSubgroup(): Promise<MonkeyTypes.CommandsSubgroup> {
251253
if (subgroupOverride !== null) {
252254
return subgroupOverride;
253255
}
254256

255257
if (usingSingleList) {
256-
return CommandlineLists.getSingleSubgroup();
258+
if (cachedSingleSubgroup === null) {
259+
cachedSingleSubgroup = await CommandlineLists.getSingleSubgroup();
260+
} else {
261+
return cachedSingleSubgroup;
262+
}
257263
}
258264

259265
return CommandlineLists.getTopOfStack();
@@ -263,10 +269,6 @@ async function getList(): Promise<MonkeyTypes.Command[]> {
263269
return (await getSubgroup()).list;
264270
}
265271

266-
async function beforeList(): Promise<void> {
267-
(await getSubgroup()).beforeList?.();
268-
}
269-
270272
async function showCommands(): Promise<void> {
271273
const element = document.querySelector("#commandLine .suggestions");
272274
if (element === null) {
@@ -442,7 +444,6 @@ async function runActiveCommand(): Promise<void> {
442444
CommandlineLists.pushToStack(
443445
command.subgroup as MonkeyTypes.CommandsSubgroup
444446
);
445-
await beforeList();
446447
updateInput("");
447448
await filterSubgroup();
448449
await showCommands();
@@ -454,7 +455,6 @@ async function runActiveCommand(): Promise<void> {
454455
void AnalyticsController.log("usedCommandLine", { command: command.id });
455456
hide();
456457
} else {
457-
await beforeList();
458458
await filterSubgroup();
459459
await showCommands();
460460
await updateActiveCommand();

frontend/src/ts/commandline/lists.ts

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -553,54 +553,37 @@ export async function getSingleSubgroup(): Promise<MonkeyTypes.CommandsSubgroup>
553553
challengesPromise,
554554
]);
555555

556-
if (singleList) return singleList;
557-
558-
// const
559-
560556
const singleCommands: MonkeyTypes.Command[] = [];
561-
const beforeListFunctions: (() => void)[] = [];
562557
for (const command of commands.list) {
563558
const ret = buildSingleListCommands(command);
564-
singleCommands.push(...ret.commands);
565-
beforeListFunctions.push(...ret.beforeListFunctions);
559+
singleCommands.push(...ret);
566560
}
567561

568562
singleList = {
569563
title: "All commands",
570564
list: singleCommands,
571-
beforeList: (): void => {
572-
for (const func of beforeListFunctions) {
573-
func();
574-
}
575-
},
576565
};
577566
return singleList;
578567
}
579568

580-
type SingleList = {
581-
commands: MonkeyTypes.Command[];
582-
beforeListFunctions: (() => void)[];
583-
};
584-
585569
function buildSingleListCommands(
586570
command: MonkeyTypes.Command,
587571
parentCommand?: MonkeyTypes.Command
588-
): SingleList {
572+
): MonkeyTypes.Command[] {
589573
const commands: MonkeyTypes.Command[] = [];
590-
const beforeListFunctions: (() => void)[] = [];
591574
if (command.subgroup) {
575+
if (command.subgroup.beforeList) {
576+
command.subgroup.beforeList();
577+
}
592578
const currentCommand = {
593579
...command,
594580
subgroup: {
595581
...command.subgroup,
596582
list: [],
597583
},
598584
};
599-
if (command.subgroup.beforeList) {
600-
beforeListFunctions.push(command.subgroup.beforeList);
601-
}
602585
for (const cmd of command.subgroup.list) {
603-
commands.push(...buildSingleListCommands(cmd, currentCommand).commands);
586+
commands.push(...buildSingleListCommands(cmd, currentCommand));
604587
}
605588
} else {
606589
if (parentCommand) {
@@ -644,8 +627,5 @@ function buildSingleListCommands(
644627
commands.push(command);
645628
}
646629
}
647-
return {
648-
commands,
649-
beforeListFunctions,
650-
};
630+
return commands;
651631
}

0 commit comments

Comments
 (0)