Support creating a slashCommand as a command shortcut
parent
a9ed194fa1
commit
e050c7a4cf
|
@ -16,10 +16,15 @@ export type Notification = {
|
||||||
export type PanelMode = number;
|
export type PanelMode = number;
|
||||||
|
|
||||||
export type Shortcut = {
|
export type Shortcut = {
|
||||||
|
// Command we're creating the shortcut for
|
||||||
|
command: string;
|
||||||
|
// (Re)bind to keyboard shortcut
|
||||||
key?: string;
|
key?: string;
|
||||||
mac?: string;
|
mac?: string;
|
||||||
|
// Bind to slash command
|
||||||
|
slashCommand?: string;
|
||||||
|
// Tweak priority in command palette
|
||||||
priority?: number;
|
priority?: number;
|
||||||
command: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ActionButton = {
|
export type ActionButton = {
|
||||||
|
|
|
@ -249,6 +249,9 @@ export class Client {
|
||||||
type: "settings-loaded",
|
type: "settings-loaded",
|
||||||
settings: this.settings,
|
settings: this.settings,
|
||||||
});
|
});
|
||||||
|
this.clientSystem.slashCommandHook.buildAllCommands(
|
||||||
|
this.clientSystem.system,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async initSync() {
|
private async initSync() {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import {
|
||||||
} from "../../plug-api/types.ts";
|
} from "../../plug-api/types.ts";
|
||||||
import { safeRun } from "$lib/async.ts";
|
import { safeRun } from "$lib/async.ts";
|
||||||
import { SlashCommandDef, SlashCommandHookT } from "$lib/manifest.ts";
|
import { SlashCommandDef, SlashCommandHookT } from "$lib/manifest.ts";
|
||||||
|
import { parseCommand } from "$common/command.ts";
|
||||||
|
|
||||||
export type AppSlashCommand = {
|
export type AppSlashCommand = {
|
||||||
slashCommand: SlashCommandDef;
|
slashCommand: SlashCommandDef;
|
||||||
|
@ -49,6 +50,26 @@ export class SlashCommandHook implements Hook<SlashCommandHookT> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (this.editor.settings?.shortcuts) {
|
||||||
|
// Add slash commands for shortcuts that configure them
|
||||||
|
for (const shortcut of this.editor.settings.shortcuts) {
|
||||||
|
if (shortcut.slashCommand) {
|
||||||
|
const parsedCommand = parseCommand(shortcut.command);
|
||||||
|
this.slashCommands.set(shortcut.slashCommand, {
|
||||||
|
slashCommand: {
|
||||||
|
name: shortcut.slashCommand,
|
||||||
|
description: parsedCommand.alias || parsedCommand.name,
|
||||||
|
},
|
||||||
|
run: () => {
|
||||||
|
return this.editor.runCommandByName(
|
||||||
|
parsedCommand.name,
|
||||||
|
parsedCommand.args,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Completer for CodeMirror
|
// Completer for CodeMirror
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#meta
|
#meta
|
||||||
|
/ind
|
||||||
This page contains settings for configuring SilverBullet and its Plugs. Changing any of these will go into effect immediately in most cases except `indexPage` which requires a page reload.
|
This page contains settings for configuring SilverBullet and its Plugs. Changing any of these will go into effect immediately in most cases except `indexPage` which requires a page reload.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -41,12 +41,19 @@ actionButtons:
|
||||||
# description: "Go to the previous page"
|
# description: "Go to the previous page"
|
||||||
# mobile: true # Only show on mobile devices, set to false to show only on desktop
|
# mobile: true # Only show on mobile devices, set to false to show only on desktop
|
||||||
|
|
||||||
# Override keyboard shortcuts and command priority
|
# Create keyboard or slash command shortcuts for commands
|
||||||
shortcuts:
|
shortcuts:
|
||||||
- command: "Navigate: Center Cursor" # But a command name is also supported
|
# Map a key to a command
|
||||||
|
- command: "{[Navigate: Center Cursor]}"
|
||||||
key: "Alt-x"
|
key: "Alt-x"
|
||||||
|
# Map a slash command (e.g. `/indent`) to a command
|
||||||
|
- command: "{[Outline: Move Right]}"
|
||||||
|
slashCommand: "indent"
|
||||||
|
- command: "{[Outline: Move Left]}"
|
||||||
|
slashCommand: "outdent"
|
||||||
|
# Bump a command's priority in the command palette
|
||||||
- command: "{[Upload: File]}"
|
- command: "{[Upload: File]}"
|
||||||
priority: 1 # Make sure this appears at the top of the list in the command palette
|
priority: 1
|
||||||
|
|
||||||
# Page decorations
|
# Page decorations
|
||||||
pageDecorations:
|
pageDecorations:
|
||||||
|
|
Loading…
Reference in New Issue