shabegom / buttons

Buttons in Obsidian
The Unlicense
455 stars 47 forks source link

prepend/append for commands #72

Closed Rhydderch closed 5 months ago

Rhydderch commented 2 years ago

Hello,

I found a bug: if the command called by the button inserts text, the text will be inserted inside the code of the button and the button will not be removed if remove=true.

To reproduce:

name Add Daily Agenda
type command
action ICS: import events
remove true

Perhaps one way to solve this would be to first remove the button then launch the command. Another way would be to let users append/prepend/etc with commands in case they return text.

Note: the bug only happens if one stays in the "preview" mode. If I click the button, then quickly switch to edit mode, the text is entered correctly.

shabegom commented 2 years ago

Ah interesting bug. It's a bit of a race between the button removal and insert the text. It definitely tries to do the removal first.

I wonder if I can make it insert below the button...

In the meantime, a workaround would be to execute the command inside a templater template and then use an append template button.

Rhydderch commented 2 years ago

I guess making it insert just below the button could work!

In the meantime, a workaround would be to execute the command inside a templater template and then use an append template button. I did not know we could call commands inside templater templates. I will check the docs (but if you have a code example at hand that would great)

shabegom commented 2 years ago

I did not know we could call commands inside templater templates. I will check the docs (but if you have a code example at hand that would great)

Yeah! So I hook into obsidian's command execution method (this is how buttons works too):

<%* app.commands.executeCommandById("ics-plugin:import_events") %>
Rhydderch commented 2 years ago

I did not know we could call commands inside templater templates. I will check the docs (but if you have a code example at hand that would great)

Yeah! So I hook into obsidian's command execution method (this is how buttons works too):

<%* app.commands.executeCommandById("ics-plugin:import_events") %>

Great, I did not know we could do this. Thanks a lot for this!