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:
prcrst
2023-11-25 18:57:00 +01:00
committed by GitHub
co-authored by prcrst Zef Hemel
parent a03b211dad
commit e6f77b12af
15 changed files with 105 additions and 17 deletions
+7
View File
@@ -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
+4
View File
@@ -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);
}
+9 -1
View File
@@ -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;
}
}
+3 -3
View File
@@ -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);
}
}