mProjectsCode / obsidian-meta-bind-plugin

A plugin for Obsidian to make your notes interactive with inline input fields, metadata displays, and buttons.
https://www.moritzjung.dev/obsidian-meta-bind-plugin-docs/
GNU General Public License v3.0
524 stars 40 forks source link

buttons - proposal to switch to ID based indentification #303

Open dxcore35 opened 6 months ago

dxcore35 commented 6 months ago

Is your Feature Request Related to a Problem?

In this list Screenshot 2024-04-22 at 18 10 19

Add auto destruct button action

Describe the Feature you'd Like

After clicking on the button the button will be removed from note. It should respect the order. For example I will asign button to export to PDF and then delete itself. The deletion should be executed the last.

Additional Context

No response

mProjectsCode commented 6 months ago

You can already achieve that with replaceSelf and an empty replacement string.

dxcore35 commented 6 months ago

Maybe just add it duplicity and call it Remove button. More clear and not much code for you to implement. The empty string is "hack" it works, but not so obvious.

dxcore35 commented 6 months ago

I just rested it unfortunately it is not working in my case for INLINE BUTTON.

ButtonMDRC >> error while running action Error: Replace self action not supported for inline buttons
    at bp.runReplaceSelfAction (plugin:obsidian-meta-bind-plugin:53:52)
    at bp.runAction (plugin:obsidian-meta-bind-plugin:51:7266)
    at bp.runButtonAction (plugin:obsidian-meta-bind-plugin:51:5233)
    at async onClick (plugin:obsidian-meta-bind-plugin:57:14387)
    at async f (plugin:obsidian-meta-bind-plugin:57:13107) 
mProjectsCode commented 6 months ago

Yep, because of a limitation in the Obsidian API. There is no way for inline buttons to know where in the file they are, and they need that to replace themselves.

dxcore35 commented 6 months ago

But inline buttons are just text no? If you know the name of button that was triggered you can simply replace the inline button as text with null no?

mProjectsCode commented 6 months ago

The same string of text might occur multiple times in the file, or even as part of something else which is not an inline button declaration. So doing a simple find and replace could result in undesirable behavior.

dxcore35 commented 6 months ago

Do you really thing somebody will add text in those brackets? BUTTON[action-summarize]? I highly doubt and other inline will also not use BUTTON as prefix. It is something to think about, I think percentage is extremely small.... Maybe just write good explanation with warning in description? will be sufficient.

This inline buttons are gold it is pitty to not have option to destroy them :)

Tejeev commented 6 months ago

@mProjectsCode it's pretty easy to work around that. The Buttons plugin generates unique identifiers for each button, and as @dxcore35 suggested, meta bind could just make use of the BUTTON[ID] syntax as their unique identifier as it's very unlikely that this will be used elsewhere. While I have not tested and so I suppose the ID may not be a unique identifier, a possible solution is to add in a unique ID if the inline button is set for self destruct on click.

Shurikus-crypto commented 4 months ago

@mProjectsCode wrote that the buttons can be remove using JS. Please show me an example of how to do this?