How to bind to a command?

Hello,

First of all I don’t know much about JS and web development so forgive me if the question is stupid :slight_smile:

I am looking for a way to bind in my plugin to such event: core:open-note. I checked documentation and also was looking in source code in some plugins, but I cannot find anything.

My ultimate goal is to keep a list of opened notes in memory and then use that to display ‘Recently opened notes’ on some key shortcut. Since I haven’t found anything like this in a plugin list, I am trying to do it myself.

Thanks for any help.

Hey
you need to add a listener in the command registry. You can do this with the following example:

inkdrop.commands.add(
  document.body,
  'core:open-note',
  (event) => {
    console.log("Note opened", event.detail.noteId);
  }
)

You can see all provided arguments (event.detail) for the command core:open-note here: List of commands - Inkdrop API Reference

For more information about the command registry take a look here: Command Registry - Inkdrop API Reference

1 Like

I was somehow fixed on a thought that by using inkdrop.commands.add I am able to only register my own commands which I can later emit.

Thank you, your reply filled my knowledge gap :slight_smile:

1 Like