Initial implementation of command link arguments (#573)
Initial implementation of command link arguments --------- Co-authored-by: prcrst <p-github@prcr.st> Co-authored-by: Zef Hemel <zef@zef.me>
This commit is contained in:
co-authored by
prcrst
Zef Hemel
parent
a03b211dad
commit
e6f77b12af
+6
-2
@@ -879,10 +879,14 @@ export class Client {
|
||||
}
|
||||
}
|
||||
|
||||
async runCommandByName(name: string) {
|
||||
async runCommandByName(name: string, args?: string[]) {
|
||||
const cmd = this.ui.viewState.commands.get(name);
|
||||
if (cmd) {
|
||||
await cmd.run();
|
||||
if (args) {
|
||||
await cmd.run(args);
|
||||
} else {
|
||||
await cmd.run();
|
||||
}
|
||||
} else {
|
||||
throw new Error(`Command ${name} not found`);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ const straightQuoteContexts = [
|
||||
"FrontMatterCode",
|
||||
"DirectiveStart",
|
||||
"Attribute",
|
||||
"CommandLink"
|
||||
];
|
||||
|
||||
// TODO: Add support for selection (put quotes around or create blockquote block?)
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ export function createEditorState(
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Promise.resolve()
|
||||
Promise.resolve([])
|
||||
.then(def.run)
|
||||
.catch((e: any) => {
|
||||
console.error(e);
|
||||
|
||||
@@ -14,7 +14,7 @@ export type CommandDef = {
|
||||
|
||||
export type AppCommand = {
|
||||
command: CommandDef;
|
||||
run: () => Promise<void>;
|
||||
run: (args?: string[]) => Promise<void>;
|
||||
};
|
||||
|
||||
export type CommandHookT = {
|
||||
@@ -43,8 +43,8 @@ export class CommandHook extends EventEmitter<CommandHookEvents>
|
||||
const cmd = functionDef.command;
|
||||
this.editorCommands.set(cmd.name, {
|
||||
command: cmd,
|
||||
run: () => {
|
||||
return plug.invoke(name, [cmd]);
|
||||
run: (args?: string[]) => {
|
||||
return plug.invoke(name, [cmd, ...args??[]]);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -50,11 +50,11 @@ export function systemSyscalls(
|
||||
}
|
||||
return plug.invoke(name, args);
|
||||
},
|
||||
"system.invokeCommand": (_ctx, name: string) => {
|
||||
"system.invokeCommand": (_ctx, name: string, args?: string[]) => {
|
||||
if (!client) {
|
||||
throw new Error("Not supported");
|
||||
}
|
||||
return client.runCommandByName(name);
|
||||
return client.runCommandByName(name, args);
|
||||
},
|
||||
"system.listCommands": (): { [key: string]: CommandDef } => {
|
||||
if (!client) {
|
||||
|
||||
Reference in New Issue
Block a user