()
| 3 | import helpers from "utils/helpers"; |
| 4 | |
| 5 | export 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 | |
| 40 | function RecentlyUsedCommands() { |
| 41 | return { |
no test coverage detected