Renamed "keyboardShortcuts" to "shortcuts"
parent
4759a20b23
commit
a205178ff0
|
@ -26,13 +26,15 @@ export function CommandPalette({
|
||||||
const isMac = isMacLike();
|
const isMac = isMacLike();
|
||||||
for (const [name, def] of commands.entries()) {
|
for (const [name, def] of commands.entries()) {
|
||||||
let shortcut: { key?: string; mac?: string } = def.command;
|
let shortcut: { key?: string; mac?: string } = def.command;
|
||||||
// Let's see if there's a keyboard shortcut override
|
// Let's see if there's a shortcut override
|
||||||
if (settings.keyboardShortcuts) {
|
if (settings.shortcuts) {
|
||||||
const commandKeyboardOverride = settings.keyboardShortcuts.find((
|
const commandKeyboardOverride = settings.shortcuts.find((
|
||||||
shortcut,
|
shortcut,
|
||||||
) => {
|
) => {
|
||||||
const commandMatch = commandLinkRegex.exec(shortcut.command);
|
const commandMatch = commandLinkRegex.exec(shortcut.command);
|
||||||
return commandMatch && commandMatch[1] === name ||
|
// If this is a command link, we want to match the command name but also make sure no arguments were set
|
||||||
|
return commandMatch && commandMatch[1] === name && !commandMatch[5] ||
|
||||||
|
// or if it's not a command link, let's match exactly
|
||||||
shortcut.command === name;
|
shortcut.command === name;
|
||||||
});
|
});
|
||||||
if (commandKeyboardOverride) {
|
if (commandKeyboardOverride) {
|
||||||
|
|
|
@ -54,22 +54,27 @@ export function createEditorState(
|
||||||
): EditorState {
|
): EditorState {
|
||||||
const commandKeyBindings: KeyBinding[] = [];
|
const commandKeyBindings: KeyBinding[] = [];
|
||||||
|
|
||||||
|
// Track which keyboard shortcuts for which commands we've overridden, so we can skip them later
|
||||||
|
const overriddenCommands = new Set<string>();
|
||||||
// Keyboard shortcuts from SETTINGS take precedense
|
// Keyboard shortcuts from SETTINGS take precedense
|
||||||
if (client.settings?.keyboardShortcuts) {
|
if (client.settings?.shortcuts) {
|
||||||
for (const shortcut of client.settings.keyboardShortcuts) {
|
for (const shortcut of client.settings.shortcuts) {
|
||||||
// console.info("Configuring keyboard shortcut", shortcut);
|
// Figure out if we're using the command link syntax here, if so: parse it out
|
||||||
|
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]}]`) : [];
|
||||||
|
}
|
||||||
|
if (args.length === 0) {
|
||||||
|
// If there was no "specialization" of this command (that is, we effectively created a keybinding for an existing command but with arguments), let's add it to the overridden command set:
|
||||||
|
overriddenCommands.add(cleanCommandName);
|
||||||
|
}
|
||||||
commandKeyBindings.push({
|
commandKeyBindings.push({
|
||||||
key: shortcut.key,
|
key: shortcut.key,
|
||||||
mac: shortcut.mac,
|
mac: shortcut.mac,
|
||||||
run: (): boolean => {
|
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) => {
|
client.runCommandByName(cleanCommandName, args).catch((e: any) => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
client.flashNotification(
|
client.flashNotification(
|
||||||
|
@ -89,6 +94,10 @@ export function createEditorState(
|
||||||
// Then add bindings for plug commands
|
// 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) {
|
||||||
|
// If we've already overridden this command, skip it
|
||||||
|
if (overriddenCommands.has(def.command.key)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
commandKeyBindings.push({
|
commandKeyBindings.push({
|
||||||
key: def.command.key,
|
key: def.command.key,
|
||||||
mac: def.command.mac,
|
mac: def.command.mac,
|
||||||
|
|
|
@ -19,17 +19,17 @@ export type Notification = {
|
||||||
|
|
||||||
export type PanelMode = number;
|
export type PanelMode = number;
|
||||||
|
|
||||||
export type KeyboardShortcut = {
|
export type Shortcut = {
|
||||||
command: string;
|
|
||||||
key?: string;
|
key?: string;
|
||||||
mac?: string;
|
mac?: string;
|
||||||
|
command: 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[];
|
shortcuts?: Shortcut[];
|
||||||
// Format: compatible with docker ignore
|
// Format: compatible with docker ignore
|
||||||
spaceIgnore?: string;
|
spaceIgnore?: string;
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,16 +15,13 @@ weeklyNotePrefix: "🗓️ "
|
||||||
weeklyNoteTemplate: "[[template/page/Weekly Note]]"
|
weeklyNoteTemplate: "[[template/page/Weekly Note]]"
|
||||||
weeklyNoteMonday: false
|
weeklyNoteMonday: false
|
||||||
|
|
||||||
# Keyboard shortcut overrides take presedence over built-in shortcuts
|
# (Keyboard) shortcut overrides take presedence over built-in shortcuts
|
||||||
keyboardShortcuts:
|
shortcuts:
|
||||||
# Using the command-link syntax
|
- mac: "Cmd-s" # Mac-specific keyboard shortcut
|
||||||
- command: "{[Stats: Show]}"
|
key: "Ctrl-s" # Windows/Linux specific keyboard shortcut
|
||||||
# Mac-specific keyboard
|
command: "{[Stats: Show]}" # Using the command link syntax here
|
||||||
mac: "Cmd-s"
|
- key: "Alt-x"
|
||||||
# Key binding for Windows/Linux (and Mac if not defined)
|
command: "Navigate: Center Cursor" # But a command name is also supported
|
||||||
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: |
|
||||||
|
|
Loading…
Reference in New Issue