diff --git a/src/button.ts b/src/button.ts index 465fde3..014e138 100644 --- a/src/button.ts +++ b/src/button.ts @@ -70,6 +70,7 @@ const clickHandler = async ( let position = inline ? await getInlineButtonPosition(app, id) : getButtonPosition(content, args); + const buttonStart = getButtonPosition(content,args); // handle command buttons if (args.templater) { args = await templater(app, position); @@ -81,6 +82,13 @@ const clickHandler = async ( replace(app, args); } + if (args.type && args.type.includes("command")) { + command(app, args, buttonStart); + } + // handle link buttons + if (args.type === "link") { + link(args); + } // handle template buttons if (args.type && args.type.includes("template")) { content = await app.vault.read(activeView.file); diff --git a/src/buttonTypes.ts b/src/buttonTypes.ts index ad13af3..0d2e89c 100644 --- a/src/buttonTypes.ts +++ b/src/buttonTypes.ts @@ -161,12 +161,23 @@ export const link = ({ action }: Arguments): void => { window.open(link); }; -export const command = (app: App, { action }: Arguments): void => { +export const command = (app: App, args: Arguments, buttonStart): void => { const allCommands = app.commands.listCommands(); + const action = args.action; const command = allCommands.filter( (command) => command.name.toUpperCase() === action.toUpperCase().trim() )[0]; - app.commands.executeCommandById(command.id); + if (args.type.includes("prepend")) { + app.workspace.getActiveViewOfType(MarkdownView).editor.setCursor(buttonStart.lineStart,0); + app.commands.executeCommandById(command.id); + } + if (args.type.includes("append")) { + app.workspace.getActiveViewOfType(MarkdownView).editor.setCursor(buttonStart.lineEnd+2,0); + app.commands.executeCommandById(command.id); + } + if (args.type === "command") { + app.commands.executeCommandById(command.id); + } }; export const swap = async ( diff --git a/src/modal.ts b/src/modal.ts index 437b9df..eb00111 100644 --- a/src/modal.ts +++ b/src/modal.ts @@ -137,6 +137,14 @@ export class ButtonModal extends Modal { new Setting(action) .setName("Command") .setDesc("Enter a command to run") + .addDropdown((drop) => { + drop.addOption("command", "Default"); + drop.addOption("prepend command", "Prepend"); + drop.addOption("apped command", "Append"); + drop.onChange((value) => { + this.outputObject.type = value; + }) + }) .addText((textEl) => { textEl.inputEl.replaceWith(this.commandSuggestEl); });