import { isMacLike } from "../../common/util.ts"; import { FilterList } from "./filter.tsx"; import { CompletionContext, CompletionResult, TerminalIcon } from "../deps.ts"; import { AppCommand } from "../hooks/command.ts"; import { BuiltinSettings, FilterOption } from "../types.ts"; import { commandLinkRegex } from "../../common/markdown_parser/parser.ts"; export function CommandPalette({ commands, recentCommands, onTrigger, vimMode, darkMode, completer, settings, }: { commands: Map; recentCommands: Map; vimMode: boolean; darkMode: boolean; completer: (context: CompletionContext) => Promise; onTrigger: (command: AppCommand | undefined) => void; settings: BuiltinSettings; }) { const options: FilterOption[] = []; const isMac = isMacLike(); for (const [name, def] of commands.entries()) { let shortcut: { key?: string; mac?: string } = def.command; // Let's see if there's a keyboard shortcut override if (settings.keyboardShortcuts) { const commandKeyboardOverride = settings.keyboardShortcuts.find(( shortcut, ) => { const commandMatch = commandLinkRegex.exec(shortcut.command); return commandMatch && commandMatch[1] === name || shortcut.command === name; }); if (commandKeyboardOverride) { shortcut = commandKeyboardOverride; } } options.push({ name: name, hint: isMac && shortcut.mac ? shortcut.mac : shortcut.key, orderId: recentCommands.has(name) ? -recentCommands.get(name)!.getTime() : 0, }); } return ( { if (opt) { onTrigger(commands.get(opt.name)); } else { onTrigger(undefined); } }} /> ); }