MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / commandPalette

Function commandPalette

src/palettes/commandPalette/index.js:5–38  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3import helpers from "utils/helpers";
4
5export default async function commandPalette() {
6 const recentCommands = RecentlyUsedCommands();
7 const { editor } = editorManager;
8 const wasFocused = editor?.hasFocus ?? false;
9
10 palette(generateHints, onselect, strings["type command"], () => {
11 if (wasFocused) editor?.focus();
12 });
13
14 function generateHints() {
15 const registeredCommands = getRegisteredCommands();
16 const hints = [];
17
18 registeredCommands.forEach(({ name, description, key }) => {
19 const keyLabel = key ? key.split("|")[0] : "";
20 const item = (recentlyUsed) => ({
21 value: name,
22 text: `<span ${recentlyUsed ? `data-str='${strings["recently used"]}'` : ""}>${description ?? name}</span><small>${keyLabel}</small>`,
23 });
24 if (recentCommands.commands.includes(name)) {
25 hints.unshift(item(true));
26 return;
27 }
28 hints.push(item(false));
29 });
30
31 return hints;
32 }
33
34 function onselect(value) {
35 const executed = executeCommand(value, editorManager.editor);
36 if (executed) recentCommands.push(value);
37 }
38}
39
40function RecentlyUsedCommands() {
41 return {

Callers 1

"command-palette"Function · 0.85

Calls 3

RecentlyUsedCommandsFunction · 0.85
paletteFunction · 0.85
focusMethod · 0.80

Tested by

no test coverage detected