From c63a93e866de3bdebd5d0001ce3225dfe9d12a29 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Tue, 2 Jan 2024 13:47:43 +0100 Subject: [PATCH] Priority support for commands and overrides --- plugs/index/index.plug.yaml | 2 ++ plugs/template/template.plug.yaml | 1 + web/components/command_palette.tsx | 13 ++++++++----- web/hooks/command.ts | 3 +++ web/types.ts | 1 + website/CHANGELOG.md | 3 ++- website/Command Palette.md | 7 +++++-- website/Commands.md | 3 +++ 8 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 website/Commands.md diff --git a/plugs/index/index.plug.yaml b/plugs/index/index.plug.yaml index a18d910..056fc95 100644 --- a/plugs/index/index.plug.yaml +++ b/plugs/index/index.plug.yaml @@ -161,6 +161,7 @@ functions: command: name: "Mentions: Toggle" key: ctrl-alt-m + priority: 5 renderMentions: path: "./linked_mentions.ts:renderMentions" @@ -172,6 +173,7 @@ functions: command: name: "Table of Contents: Toggle" key: ctrl-alt-t + priority: 5 renderTOC: path: toc.ts:renderTOC diff --git a/plugs/template/template.plug.yaml b/plugs/template/template.plug.yaml index aa71553..29ba000 100644 --- a/plugs/template/template.plug.yaml +++ b/plugs/template/template.plug.yaml @@ -102,6 +102,7 @@ functions: command: name: "Quick Note" key: "Alt-Shift-n" + priority: 3 dailyNoteCommand: path: ./template.ts:dailyNoteCommand diff --git a/web/components/command_palette.tsx b/web/components/command_palette.tsx index ef3f811..e7d45e7 100644 --- a/web/components/command_palette.tsx +++ b/web/components/command_palette.tsx @@ -25,10 +25,11 @@ export function CommandPalette({ const options: FilterOption[] = []; const isMac = isMacLike(); for (const [name, def] of commands.entries()) { - let shortcut: { key?: string; mac?: string } = def.command; + let shortcut: { key?: string; mac?: string; priority?: number } = + def.command; // Let's see if there's a shortcut override if (settings.shortcuts) { - const commandKeyboardOverride = settings.shortcuts.find(( + const commandOverride = settings.shortcuts.find(( shortcut, ) => { const commandMatch = commandLinkRegex.exec(shortcut.command); @@ -37,8 +38,9 @@ export function CommandPalette({ // or if it's not a command link, let's match exactly shortcut.command === name; }); - if (commandKeyboardOverride) { - shortcut = commandKeyboardOverride; + if (commandOverride) { + shortcut = commandOverride; + console.log(`Shortcut override for ${name}:`, shortcut); } } options.push({ @@ -46,8 +48,9 @@ export function CommandPalette({ hint: isMac && shortcut.mac ? shortcut.mac : shortcut.key, orderId: recentCommands.has(name) ? -recentCommands.get(name)!.getTime() - : 0, + : shortcut.priority || Infinity, }); + // console.log("Options", options); } return (