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
@@ -226,3 +226,10 @@ functions:
|
||||
path: ./upload.ts:uploadFile
|
||||
command:
|
||||
name: "Upload: File"
|
||||
|
||||
customFlashMessage:
|
||||
path: editor.ts:customFlashMessage
|
||||
command:
|
||||
name: "Flash: Custom Message"
|
||||
contexts:
|
||||
- internal
|
||||
@@ -50,3 +50,7 @@ export async function moveToPosCommand() {
|
||||
const pos = +posString;
|
||||
await editor.moveCursor(pos);
|
||||
}
|
||||
|
||||
export async function customFlashMessage(_ctx: any, message: string) {
|
||||
await editor.flashNotification(message);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,15 @@ async function actionClickOrActionEnter(
|
||||
}
|
||||
case "CommandLink": {
|
||||
const commandName = mdTree.children![1]!.children![0].text!;
|
||||
await system.invokeCommand(commandName);
|
||||
const argsNode = findNodeOfType(mdTree, "CommandLinkArgs");
|
||||
const argsText = argsNode?.children![0]?.text;
|
||||
// Assume the arguments are can be parsed as the innards of a valid JSON list
|
||||
try {
|
||||
const args = argsText ? JSON.parse(`[${argsText}]`) : [];
|
||||
await system.invokeCommand(commandName, args);
|
||||
} catch(e: any) {
|
||||
await editor.flashNotification(`Error parsing command link arguments: ${e.message}`, "error");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ async function saveFile(file: UploadFile) {
|
||||
editor.insertAtCursor(attachmentMarkdown);
|
||||
}
|
||||
|
||||
export async function uploadFile() {
|
||||
const uploadFile = await editor.uploadFile();
|
||||
export async function uploadFile(_ctx: any, accept?: string, capture?: string) {
|
||||
const uploadFile = await editor.uploadFile(accept, capture);
|
||||
await saveFile(uploadFile);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user