Skip to content

Commit

Permalink
impr(commandline): when searching, allow display and alias matching a…
Browse files Browse the repository at this point in the history
…t the same time
  • Loading branch information
Miodec committed Apr 26, 2024
1 parent 94bf02d commit 04ae04d
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions frontend/src/ts/commandline/commandline.ts
Expand Up @@ -174,19 +174,35 @@ async function filterSubgroup(): Promise<void> {
const inputSplit =
inputNoQuickSingle.length === 0 ? [] : inputNoQuickSingle.split(" ");

const matches: {
displayMatchCount: number;
aliasMatchCount: number;
aliasCount: number;
}[] = [];

const displayMatchCounts: number[] = [];
const aliasMatchCounts: number[] = [];
for (const command of list) {
const isAvailable = command.available?.() ?? true;
if (!isAvailable) {
displayMatchCounts.push(-1);
aliasMatchCounts.push(-1);
matches.push({
displayMatchCount: -1,
aliasMatchCount: -1,
aliasCount: 0,
});
continue;
}

if (inputNoQuickSingle.length === 0 || inputSplit.length === 0) {
displayMatchCounts.push(0);
aliasMatchCounts.push(0);
matches.push({
displayMatchCount: 0,
aliasMatchCount: 0,
aliasCount: 0,
});
continue;
}

Expand Down Expand Up @@ -234,12 +250,22 @@ async function filterSubgroup(): Promise<void> {

displayMatchCounts.push(displayMatchCount);
aliasMatchCounts.push(aliasMatchCount);
matches.push({
displayMatchCount,
aliasMatchCount,
aliasCount: aliasSplit.length,
});
}

for (const [index, command] of list.entries()) {
const match = matches[index];
if (match === undefined) {
command.found = false;
continue;
}
if (
(displayMatchCounts[index] as number) >= inputSplit.length ||
(aliasMatchCounts[index] as number) >= inputSplit.length
match.displayMatchCount >= inputSplit.length ||
(match.aliasCount > 0 && match.aliasMatchCount >= 1)
) {
command.found = true;
} else {
Expand Down

0 comments on commit 04ae04d

Please sign in to comment.