Skip to content

Commit

Permalink
Priority support for commands and overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
zefhemel committed Jan 2, 2024
1 parent fd6f7c2 commit c63a93e
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 8 deletions.
2 changes: 2 additions & 0 deletions plugs/index/index.plug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ functions:
command:
name: "Mentions: Toggle"
key: ctrl-alt-m
priority: 5

renderMentions:
path: "./linked_mentions.ts:renderMentions"
Expand All @@ -172,6 +173,7 @@ functions:
command:
name: "Table of Contents: Toggle"
key: ctrl-alt-t
priority: 5

renderTOC:
path: toc.ts:renderTOC
Expand Down
1 change: 1 addition & 0 deletions plugs/template/template.plug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ functions:
command:
name: "Quick Note"
key: "Alt-Shift-n"
priority: 3

dailyNoteCommand:
path: ./template.ts:dailyNoteCommand
Expand Down
13 changes: 8 additions & 5 deletions web/components/command_palette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -37,17 +38,19 @@ 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({
name: name,
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
Expand Down
3 changes: 3 additions & 0 deletions web/hooks/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions web/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type PanelMode = number;
export type Shortcut = {
key?: string;
mac?: string;
priority?: number;
command: string;
};

Expand Down
3 changes: 2 additions & 1 deletion website/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---

Expand Down
7 changes: 5 additions & 2 deletions website/Command Palette.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
The Command Palette is used to explore SilverBullet’s numerous commands as well as execute them.
The Command Palette is used to explore SilverBullet’s 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.
* 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 changes: 3 additions & 0 deletions website/Commands.md
Original file line number Diff line number Diff line change
@@ -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]]).

0 comments on commit c63a93e

Please sign in to comment.