Update keyboard shortcuts in command pallette #605
parent
c709f4e4be
commit
8a181145ad
|
@ -2,7 +2,8 @@ import { isMacLike } from "../../common/util.ts";
|
||||||
import { FilterList } from "./filter.tsx";
|
import { FilterList } from "./filter.tsx";
|
||||||
import { CompletionContext, CompletionResult, TerminalIcon } from "../deps.ts";
|
import { CompletionContext, CompletionResult, TerminalIcon } from "../deps.ts";
|
||||||
import { AppCommand } from "../hooks/command.ts";
|
import { AppCommand } from "../hooks/command.ts";
|
||||||
import { FilterOption } from "../types.ts";
|
import { BuiltinSettings, FilterOption } from "../types.ts";
|
||||||
|
import { commandLinkRegex } from "../../common/markdown_parser/parser.ts";
|
||||||
|
|
||||||
export function CommandPalette({
|
export function CommandPalette({
|
||||||
commands,
|
commands,
|
||||||
|
@ -11,6 +12,7 @@ export function CommandPalette({
|
||||||
vimMode,
|
vimMode,
|
||||||
darkMode,
|
darkMode,
|
||||||
completer,
|
completer,
|
||||||
|
settings,
|
||||||
}: {
|
}: {
|
||||||
commands: Map<string, AppCommand>;
|
commands: Map<string, AppCommand>;
|
||||||
recentCommands: Map<string, Date>;
|
recentCommands: Map<string, Date>;
|
||||||
|
@ -18,13 +20,28 @@ export function CommandPalette({
|
||||||
darkMode: boolean;
|
darkMode: boolean;
|
||||||
completer: (context: CompletionContext) => Promise<CompletionResult | null>;
|
completer: (context: CompletionContext) => Promise<CompletionResult | null>;
|
||||||
onTrigger: (command: AppCommand | undefined) => void;
|
onTrigger: (command: AppCommand | undefined) => void;
|
||||||
|
settings: BuiltinSettings;
|
||||||
}) {
|
}) {
|
||||||
const options: FilterOption[] = [];
|
const options: FilterOption[] = [];
|
||||||
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's see if there's a keyboard shortcut override
|
||||||
|
if (settings.keyboardShortcuts) {
|
||||||
|
const commandKeyboardOverride = settings.keyboardShortcuts.find((
|
||||||
|
shortcut,
|
||||||
|
) => {
|
||||||
|
const commandMatch = commandLinkRegex.exec(shortcut.command);
|
||||||
|
return commandMatch && commandMatch[1] === name ||
|
||||||
|
shortcut.command === name;
|
||||||
|
});
|
||||||
|
if (commandKeyboardOverride) {
|
||||||
|
shortcut = commandKeyboardOverride;
|
||||||
|
}
|
||||||
|
}
|
||||||
options.push({
|
options.push({
|
||||||
name: name,
|
name: name,
|
||||||
hint: isMac && def.command.mac ? def.command.mac : def.command.key,
|
hint: isMac && shortcut.mac ? shortcut.mac : shortcut.key,
|
||||||
orderId: recentCommands.has(name)
|
orderId: recentCommands.has(name)
|
||||||
? -recentCommands.get(name)!.getTime()
|
? -recentCommands.get(name)!.getTime()
|
||||||
: 0,
|
: 0,
|
||||||
|
|
|
@ -140,6 +140,7 @@ export class MainUI {
|
||||||
darkMode={viewState.uiOptions.darkMode}
|
darkMode={viewState.uiOptions.darkMode}
|
||||||
completer={client.miniEditorComplete.bind(client)}
|
completer={client.miniEditorComplete.bind(client)}
|
||||||
recentCommands={viewState.recentCommands}
|
recentCommands={viewState.recentCommands}
|
||||||
|
settings={this.client.settings}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{viewState.showFilterBox && (
|
{viewState.showFilterBox && (
|
||||||
|
|
Loading…
Reference in New Issue