mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
refactor(command_palette): reduce duplication
This commit is contained in:
parent
c09e124805
commit
e8b16287e0
@ -83,26 +83,13 @@ async function autocompleteSource(term: string, cb: (rows: Suggestion[]) => void
|
|||||||
if (options.isCommandPalette && term.startsWith(">")) {
|
if (options.isCommandPalette && term.startsWith(">")) {
|
||||||
const commandQuery = term.substring(1).trim();
|
const commandQuery = term.substring(1).trim();
|
||||||
|
|
||||||
if (commandQuery.length === 0) {
|
// Get commands (all if no query, filtered if query provided)
|
||||||
// Show all commands if no query
|
const commands = commandQuery.length === 0
|
||||||
const allCommands = commandRegistry.getAllCommands();
|
? commandRegistry.getAllCommands()
|
||||||
const commandSuggestions: Suggestion[] = allCommands.map(cmd => ({
|
: commandRegistry.searchCommands(commandQuery);
|
||||||
action: "command",
|
|
||||||
commandId: cmd.id,
|
// Convert commands to suggestions
|
||||||
noteTitle: cmd.name,
|
const commandSuggestions: Suggestion[] = commands.map(cmd => ({
|
||||||
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 => ({
|
|
||||||
action: "command",
|
action: "command",
|
||||||
commandId: cmd.id,
|
commandId: cmd.id,
|
||||||
noteTitle: cmd.name,
|
noteTitle: cmd.name,
|
||||||
@ -112,6 +99,7 @@ async function autocompleteSource(term: string, cb: (rows: Suggestion[]) => void
|
|||||||
commandShortcut: cmd.shortcut,
|
commandShortcut: cmd.shortcut,
|
||||||
icon: cmd.icon
|
icon: cmd.icon
|
||||||
}));
|
}));
|
||||||
|
|
||||||
cb(commandSuggestions);
|
cb(commandSuggestions);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user