Priority support for commands and overrides
This commit is contained in:
@@ -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);
|
||||
@@ -37,8 +38,9 @@ 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({
|
||||
@@ -46,8 +48,9 @@ export function CommandPalette({
|
||||
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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -22,6 +22,7 @@ export type PanelMode = number;
|
||||
export type Shortcut = {
|
||||
key?: string;
|
||||
mac?: string;
|
||||
priority?: number;
|
||||
command: string;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user