Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(command_palette): reduce duplication
Elian Dorane8b16287e039
diff --git a/apps/client/src/services/note_autocomplete.ts b/apps/client/src/services/note_autocomplete.tsindex 5b30494d49..f6ada19674 100644--- a/apps/client/src/services/note_autocomplete.ts+++ b/apps/client/src/services/note_autocomplete.ts@@ -83,26 +83,13 @@ async function autocompleteSource(term: string, cb: (rows: Suggestion[]) => voidif (options.isCommandPalette && term.startsWith(">")) {const commandQuery = term.substring(1).trim();- if (commandQuery.length === 0) {- // Show all commands if no query- const allCommands = commandRegistry.getAllCommands();- const commandSuggestions: Suggestion[] = allCommands.map(cmd => ({- action: "command",- commandId: cmd.id,- noteTitle: cmd.name,- notePathTitle: `>${cmd.name}`,- highlightedNotePathTitle: cmd.name,- commandDescription: cmd.description,- commandShortcut: cmd.shortcut,- icon: cmd.icon- }));- cb(commandSuggestions);- return;- }-- // Search commands- const matchedCommands = commandRegistry.searchCommands(commandQuery);- const commandSuggestions: Suggestion[] = matchedCommands.map(cmd => ({+ // Get commands (all if no query, filtered if query provided)+ const commands = commandQuery.length === 0+ ? commandRegistry.getAllCommands()+ : commandRegistry.searchCommands(commandQuery);++ // Convert commands to suggestions+ const commandSuggestions: Suggestion[] = commands.map(cmd => ({action: "command",commandId: cmd.id,noteTitle: cmd.name,@@ -112,6 +99,7 @@ async function autocompleteSource(term: string, cb: (rows: Suggestion[]) => voidcommandShortcut: cmd.shortcut,icon: cmd.icon}));+cb(commandSuggestions);return;}