1
0

Priority support for commands and overrides

This commit is contained in:
Zef Hemel 2024-01-02 13:47:43 +01:00
parent fd6f7c28c9
commit c63a93e866
8 changed files with 25 additions and 8 deletions

View File

@ -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

View File

@ -102,6 +102,7 @@ functions:
command:
name: "Quick Note"
key: "Alt-Shift-n"
priority: 3
dailyNoteCommand:
path: ./template.ts:dailyNoteCommand

View File

@ -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 (
<FilterList

View File

@ -7,6 +7,9 @@ export type CommandDef = {
contexts?: string[];
// Default 0, higher is higher priority = higher in the list
priority?: number;
// Bind to keyboard shortcut
key?: string;
mac?: string;

View File

@ -22,6 +22,7 @@ export type PanelMode = number;
export type Shortcut = {
key?: string;
mac?: string;
priority?: number;
command: string;
};

View File

@ -4,7 +4,8 @@ release.
---
## Next
* Keyboard shortcuts can now be configured in [[SETTINGS]]
* Keyboard shortcuts as well as priority (order in which they appear in the [[Command Palette]]) can now be configured for [[Commands]] in [[SETTINGS]]. The `priority` enables you to put frequently used commands at the top.
* The rendering of [[Live Templates]], [[Live Queries]], [[Table of Contents]] and [[Linked Mentions]] has been re-implemented. Rendering should now be near-instant and the “flappy” behavior should be largely gone, especially after an initial load (results are cached). There may still be some visual regressions. Please report them if you find them.
---

View File

@ -1,5 +1,8 @@
The Command Palette is used to explore SilverBullets numerous commands as well as execute them.
The Command Palette is used to explore SilverBullets numerous [[Commands]] as well as execute them.
The UI and its operation is largely the same as the [[Page Picker]]s, with a few differences:
* If a keyboard shortcut is configured for the given command, it is listed along the command name to the right.
* The ordering is decided based on two factors:
* The last time the command was invoked via the [[Command Palette]] in this client session.
* The `priority` configured for the command (in the plug, or via [[SETTINGS]] under `shortcuts`).

3
website/Commands.md Normal file
View File

@ -0,0 +1,3 @@
Commands define actions that SilverBullet can perform. They range from simple edit commands, such as {[Text: Bold]}, but may be more elaborate such as {[Page: Rename]}. At a technical level, all commands are implemented via [[Plugs]].
All available commands appear in the [[Command Palette]] but may have key bindings as well (these key bindings appear in the [[Command Palette]] and are configurable in [[SETTINGS]]).