Fixes #605
This commit is contained in:
parent
333eb8c151
commit
df83c62dec
@ -930,7 +930,7 @@ export class Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async runCommandByName(name: string, args?: string[]) {
|
async runCommandByName(name: string, args?: any[]) {
|
||||||
const cmd = this.ui.viewState.commands.get(name);
|
const cmd = this.ui.viewState.commands.get(name);
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
if (args) {
|
if (args) {
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import buildMarkdown from "../common/markdown_parser/parser.ts";
|
import buildMarkdown, {
|
||||||
|
commandLinkRegex,
|
||||||
|
} from "../common/markdown_parser/parser.ts";
|
||||||
import { readonlyMode } from "./cm_plugins/readonly.ts";
|
import { readonlyMode } from "./cm_plugins/readonly.ts";
|
||||||
import customMarkdownStyle from "./style.ts";
|
import customMarkdownStyle from "./style.ts";
|
||||||
import {
|
import {
|
||||||
@ -51,6 +53,40 @@ export function createEditorState(
|
|||||||
readOnly: boolean,
|
readOnly: boolean,
|
||||||
): EditorState {
|
): EditorState {
|
||||||
const commandKeyBindings: KeyBinding[] = [];
|
const commandKeyBindings: KeyBinding[] = [];
|
||||||
|
|
||||||
|
// Keyboard shortcuts from SETTINGS take precedense
|
||||||
|
if (client.settings?.keyboardShortcuts) {
|
||||||
|
for (const shortcut of client.settings.keyboardShortcuts) {
|
||||||
|
console.info("Configuring keyboard shortcut", shortcut);
|
||||||
|
commandKeyBindings.push({
|
||||||
|
key: shortcut.key,
|
||||||
|
mac: shortcut.mac,
|
||||||
|
run: (): boolean => {
|
||||||
|
const commandMatch = commandLinkRegex.exec(shortcut.command);
|
||||||
|
|
||||||
|
let cleanCommandName = shortcut.command;
|
||||||
|
let args: any[] = [];
|
||||||
|
if (commandMatch) {
|
||||||
|
cleanCommandName = commandMatch[1];
|
||||||
|
args = commandMatch[5] ? JSON.parse(`[${commandMatch[5]}]`) : [];
|
||||||
|
}
|
||||||
|
client.runCommandByName(cleanCommandName, args).catch((e: any) => {
|
||||||
|
console.error(e);
|
||||||
|
client.flashNotification(
|
||||||
|
`Error running command: ${e.message}`,
|
||||||
|
"error",
|
||||||
|
);
|
||||||
|
}).then(() => {
|
||||||
|
// Always be focusing the editor after running a command
|
||||||
|
client.focus();
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then add bindings for plug commands
|
||||||
for (const def of client.system.commandHook.editorCommands.values()) {
|
for (const def of client.system.commandHook.editorCommands.values()) {
|
||||||
if (def.command.key) {
|
if (def.command.key) {
|
||||||
commandKeyBindings.push({
|
commandKeyBindings.push({
|
||||||
@ -81,6 +117,7 @@ export function createEditorState(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let touchCount = 0;
|
let touchCount = 0;
|
||||||
|
|
||||||
const markdownLanguage = buildMarkdown(client.system.mdExtensions);
|
const markdownLanguage = buildMarkdown(client.system.mdExtensions);
|
||||||
|
@ -14,7 +14,7 @@ export type CommandDef = {
|
|||||||
|
|
||||||
export type AppCommand = {
|
export type AppCommand = {
|
||||||
command: CommandDef;
|
command: CommandDef;
|
||||||
run: (args?: string[]) => Promise<void>;
|
run: (args?: any[]) => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CommandHookT = {
|
export type CommandHookT = {
|
||||||
@ -44,7 +44,7 @@ export class CommandHook extends EventEmitter<CommandHookEvents>
|
|||||||
this.editorCommands.set(cmd.name, {
|
this.editorCommands.set(cmd.name, {
|
||||||
command: cmd,
|
command: cmd,
|
||||||
run: (args?: string[]) => {
|
run: (args?: string[]) => {
|
||||||
return plug.invoke(name, [cmd, ...args??[]]);
|
return plug.invoke(name, [cmd, ...args ?? []]);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,17 @@ export type Notification = {
|
|||||||
|
|
||||||
export type PanelMode = number;
|
export type PanelMode = number;
|
||||||
|
|
||||||
|
export type KeyboardShortcut = {
|
||||||
|
command: string;
|
||||||
|
key?: string;
|
||||||
|
mac?: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type BuiltinSettings = {
|
export type BuiltinSettings = {
|
||||||
indexPage: string;
|
indexPage: string;
|
||||||
customStyles?: string | string[];
|
customStyles?: string | string[];
|
||||||
plugOverrides?: Record<string, Partial<Manifest>>;
|
plugOverrides?: Record<string, Partial<Manifest>>;
|
||||||
|
keyboardShortcuts?: KeyboardShortcut[];
|
||||||
// Format: compatible with docker ignore
|
// Format: compatible with docker ignore
|
||||||
spaceIgnore?: string;
|
spaceIgnore?: string;
|
||||||
};
|
};
|
||||||
|
@ -3,6 +3,11 @@ release.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Next
|
||||||
|
* Keyboard shortcuts can now be configured in [[SETTINGS]]
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 0.5.10
|
## 0.5.10
|
||||||
* **Breaking change**: Local attachment URLs (`[page](url)` syntax and `![alt](url)` image syntax) are now interpreted to relative to the page's folder, unless their URL starts with a `/` then they're relative to the space root (as per [this issue](https://github.com/silverbulletmd/silverbullet/issues/363))
|
* **Breaking change**: Local attachment URLs (`[page](url)` syntax and `![alt](url)` image syntax) are now interpreted to relative to the page's folder, unless their URL starts with a `/` then they're relative to the space root (as per [this issue](https://github.com/silverbulletmd/silverbullet/issues/363))
|
||||||
* **Breaking change:** Revamped [[Templates]], specifically changed the format of [[Page Templates]]. The “Template: Instantiate Page” has been renamed to {[Page: From Template]}.
|
* **Breaking change:** Revamped [[Templates]], specifically changed the format of [[Page Templates]]. The “Template: Instantiate Page” has been renamed to {[Page: From Template]}.
|
||||||
|
@ -7,29 +7,29 @@ indexPage: "[[SilverBullet]]"
|
|||||||
# Load custom CSS styles from the following page, can also be an array
|
# Load custom CSS styles from the following page, can also be an array
|
||||||
customStyles: "[[STYLES]]"
|
customStyles: "[[STYLES]]"
|
||||||
|
|
||||||
|
# Template settings
|
||||||
quickNotePrefix: "📥 "
|
quickNotePrefix: "📥 "
|
||||||
|
|
||||||
dailyNotePrefix: "📅 "
|
dailyNotePrefix: "📅 "
|
||||||
dailyNoteTemplate: "[[template/page/Daily Note]]"
|
dailyNoteTemplate: "[[template/page/Daily Note]]"
|
||||||
|
|
||||||
weeklyNotePrefix: "🗓️ "
|
weeklyNotePrefix: "🗓️ "
|
||||||
weeklyNoteTemplate: "[[template/page/Weekly Note]]"
|
weeklyNoteTemplate: "[[template/page/Weekly Note]]"
|
||||||
weeklyNoteMonday: false
|
weeklyNoteMonday: false
|
||||||
|
|
||||||
# Markdown
|
# Keyboard shortcut overrides take presedence over built-in shortcuts
|
||||||
previewOnRHS: true
|
keyboardShortcuts:
|
||||||
|
# Using the command-link syntax
|
||||||
|
- command: "{[Stats: Show]}"
|
||||||
|
# Mac-specific keyboard
|
||||||
|
mac: "Cmd-s"
|
||||||
|
# Key binding for Windows/Linux (and Mac if not defined)
|
||||||
|
key: "Ctrl-s"
|
||||||
|
- command: "Navigate: Center Cursor"
|
||||||
|
key: "Alt-x"
|
||||||
|
|
||||||
# Defines files to ignore in a format compatible with .gitignore
|
# Defines files to ignore in a format compatible with .gitignore
|
||||||
spaceIgnore: |
|
spaceIgnore: |
|
||||||
dist
|
dist
|
||||||
largefolder
|
largefolder
|
||||||
*.mp4
|
*.mp4
|
||||||
# Plug overrides allow you to override any property in a plug manifest at runtime
|
|
||||||
# The primary use case of this is to override or define keyboard shortcuts. You can use the . notation, to quickly "dive deep" into the structure
|
|
||||||
plugOverrides:
|
|
||||||
editor:
|
|
||||||
# Matching this YAML structure:
|
|
||||||
# https://github.com/silverbulletmd/silverbullet/blob/main/plugs/editor/editor.plug.yaml
|
|
||||||
# and overriding the "key" for centering the cursor
|
|
||||||
functions.centerCursor.command.key: Ctrl-Alt-p
|
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user