Skip to content

Commit

Permalink
fix(commandline): presets and tags not showing up in single list mode
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Miodec committed Mar 13, 2024
1 parent c1b71fb commit 3aeba30
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 35 deletions.
16 changes: 8 additions & 8 deletions frontend/src/ts/commandline/commandline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function show(
inputValue = "";
activeIndex = 0;
mode = "search";
cachedSingleSubgroup = null;
inputModeParams = {
command: null,
placeholder: null,
Expand Down Expand Up @@ -97,7 +98,6 @@ export function show(
activeCommand = null;
Focus.set(false);
CommandlineLists.setStackToDefault();
await beforeList();
updateInput();
await filterSubgroup();
await showCommands();
Expand Down Expand Up @@ -247,13 +247,19 @@ function hideCommands(): void {
element.innerHTML = "";
}

let cachedSingleSubgroup: MonkeyTypes.CommandsSubgroup | null = null;

async function getSubgroup(): Promise<MonkeyTypes.CommandsSubgroup> {
if (subgroupOverride !== null) {
return subgroupOverride;
}

if (usingSingleList) {
return CommandlineLists.getSingleSubgroup();
if (cachedSingleSubgroup === null) {
cachedSingleSubgroup = await CommandlineLists.getSingleSubgroup();
} else {
return cachedSingleSubgroup;
}
}

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

async function beforeList(): Promise<void> {
(await getSubgroup()).beforeList?.();
}

async function showCommands(): Promise<void> {
const element = document.querySelector("#commandLine .suggestions");
if (element === null) {
Expand Down Expand Up @@ -442,7 +444,6 @@ async function runActiveCommand(): Promise<void> {
CommandlineLists.pushToStack(
command.subgroup as MonkeyTypes.CommandsSubgroup
);
await beforeList();
updateInput("");
await filterSubgroup();
await showCommands();
Expand All @@ -454,7 +455,6 @@ async function runActiveCommand(): Promise<void> {
void AnalyticsController.log("usedCommandLine", { command: command.id });
hide();
} else {
await beforeList();
await filterSubgroup();
await showCommands();
await updateActiveCommand();
Expand Down
34 changes: 7 additions & 27 deletions frontend/src/ts/commandline/lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,54 +553,37 @@ export async function getSingleSubgroup(): Promise<MonkeyTypes.CommandsSubgroup>
challengesPromise,
]);

if (singleList) return singleList;

// const

const singleCommands: MonkeyTypes.Command[] = [];
const beforeListFunctions: (() => void)[] = [];
for (const command of commands.list) {
const ret = buildSingleListCommands(command);
singleCommands.push(...ret.commands);
beforeListFunctions.push(...ret.beforeListFunctions);
singleCommands.push(...ret);
}

singleList = {
title: "All commands",
list: singleCommands,
beforeList: (): void => {
for (const func of beforeListFunctions) {
func();
}
},
};
return singleList;
}

type SingleList = {
commands: MonkeyTypes.Command[];
beforeListFunctions: (() => void)[];
};

function buildSingleListCommands(
command: MonkeyTypes.Command,
parentCommand?: MonkeyTypes.Command
): SingleList {
): MonkeyTypes.Command[] {
const commands: MonkeyTypes.Command[] = [];
const beforeListFunctions: (() => void)[] = [];
if (command.subgroup) {
if (command.subgroup.beforeList) {
command.subgroup.beforeList();
}
const currentCommand = {
...command,
subgroup: {
...command.subgroup,
list: [],
},
};
if (command.subgroup.beforeList) {
beforeListFunctions.push(command.subgroup.beforeList);
}
for (const cmd of command.subgroup.list) {
commands.push(...buildSingleListCommands(cmd, currentCommand).commands);
commands.push(...buildSingleListCommands(cmd, currentCommand));
}
} else {
if (parentCommand) {
Expand Down Expand Up @@ -644,8 +627,5 @@ function buildSingleListCommands(
commands.push(command);
}
}
return {
commands,
beforeListFunctions,
};
return commands;
}

0 comments on commit 3aeba30

Please sign in to comment.