Elffuss BraidHub

kikocis/continue public

main · 765 BRawPermalink
1import { SlashCommandDescWithSource } from "core";
2import {} from "core/config/default";
3
4/**
5 * Sorts commands with bookmarked ones first
6 * @param commands The list of commands to sort
7 * @param bookmarkedCommands An array of bookmarked command names
8 * @returns A new sorted array with bookmarked commands first
9 */
10export function sortCommandsByBookmarkStatus(
11 commands: SlashCommandDescWithSource[],
12 bookmarkedCommands: string[],
13): SlashCommandDescWithSource[] {
14 return [...commands].sort((a, b) => {
15 const aIsBookmarked = bookmarkedCommands.includes(a.name);
16 const bIsBookmarked = bookmarkedCommands.includes(b.name);
17
18 if (aIsBookmarked && !bIsBookmarked) return -1;
19 if (!aIsBookmarked && bIsBookmarked) return 1;
20 return 0;
21 });
22}