shabegom / buttons

Buttons in Obsidian
The Unlicense
455 stars 47 forks source link

Bug: replace not working #23

Closed Scarlov closed 3 years ago

Scarlov commented 3 years ago

After the most recent update the "replace" option in my buttons with prepend template, stopped working completely.

   ```button
   name Refresh
   type prepend template
   action weather_window
   replace ## R
   color blue
   \```

I used it to refresh a weather template window I put in my daily notes.

shabegom commented 3 years ago

Hey @Scarlov, sorry for breaking your button!

I've changed the replace arg to be a bit more reliable. It now uses an array: [startingLineNumber, endingLineNumber]

So, for example if your weather_window template started on line 5 and ended on line 10, your button would be:

```button name Refresh type prepend template action weather_window replace [5,10] color blue ```

Let me know if this change is going to cause any problems. It allows for replace to also be used with append template and I'm going to add an insert template type that let's you add content anywhere in the note.

Scarlov commented 3 years ago

Oh that's actually much more useful then before! Sounds great actually. I have already remade my buttons with this and thy work just as before, great idea to add that feature. While rewriting the button I had an idea that with this you could maybe also target the lines in respect to the button code block, for example:

   ```button
   name Refresh
   type prepend template
   action weather_window
   replace [-5,-3]
   color blue
   \```

would instead target are that is between 5 and 3 line before the code block. But that's just a random idea. Love your plugin, thank you for you contributions to Obsidian!

shabegom commented 3 years ago

I'll add that to the list of ideas! Thank you!