Two questions for my tag plugin

I'm in the process of writing a plugin so that when you click on a tag at the bottom of the screen the note will scroll to a location where there is a (hidden) comment matching the selected tag.

I have set up a basic plugin and managed to parse the current note creating an array of the comments and line numbers. Now I'm not even sure if the the available plugin development code will allow me to do this but...

a) The selected tags are currently displayed in a pane at the bottom of the note in a DIV with a class of 'tag-list'. I've set up webview with an event listener to capture a click on this panel, but it does not seems to trigger? Is this something that is currently outside the scope of the development framework? If so, could it be included please? It would also be better if the SPANS within this DIV displaying the individual tags had their own class, something like 'tag-name'. Getting the name of the clicked tag will then be so much easier.

b) I assume that I will need to scroll the note to the appropriate location using 'scrollY' ? Is there any documentation that I can read that better explains these calls, or do I need to search the main code to find out how things work?

Thanks in advance.

Can the admins/developers offer any advice please on the above? I've got nowhere else to turn to get answers.

Am I wasting my time with this plugin as the architecture won't support it?

Can only comment on this one - I think it's safe to assume that even if there's documentation you still need to look in the code.

Please have a look at the TOC plugin as it does something similar, in particular triggering some action when a link is clicked: joplin/packages/app-cli/tests/support/plugins/toc at dev · laurent22/joplin · GitHub

b) I assume that I will need to scroll the note to the appropriate location using 'scrollY'

There's a scrollToHash function, so you could add invisible anchors in the document and scroll to that.

Thanks for the reply Laurent, I know how busy you are.

I have already got as far as I have by looking at the suggested plugin. In fact, I've had a look at most of the plugins to try and understand the plugin architecture better, which I know is a work in progress.

I have set up a web view with a click event listener, but all the published plugins seem to listen to on forms created by the plugin i.e. await joplin.views.panels.onMessage(). How do I receive a message from a component not created by the plug please?

Lastly, have you given any thought as to whether a new class could be introduced for the SPAN inside the DIV with the class of 'tag-list'. I can see no other way of getting the specific tag that has been clicked on unless it has either a unique ID (not required in this case), or CLASS that the event listener can pick up on.

Listening to events on components outside your own is not and will not be supported. It's best to describe at a higher level what you want to do, and see if that can be added to the plugin system.

Ah, okay, that's why I couldn't get any further with my plugin.

Here's what I'm trying to do...

I have stored many legal documents as notes. They can be many pages long; some, twenty or thirty pages in length. As they are legal documents, I cannot alter what is seen in the viewer, but could obviously put hidden comments in the source.

I tag the notes according to the contents of the documents. It's important to note that the tags are not necessarily found in the document itself, so if a document was tagged with 'legal obligation', it's not because that phrase is in the document, but because part or parts of the document relates to the tag (key word). It may be that a document has two sections or more in it which relate to a particular tag. So in a twenty page document, there may be two sentences, or even three whole paragraphs which warrant the tag being putting on in the first place.

Like others, all my notes may have more than one tag, and any tag can be used on multiple documents.

Using my example, if I search for a particular tag, I am presented with all notes that has this particular tag. However, when I open one of these documents, I have no way of knowing which section of the document warranted putting the tag on. i.e. I'd like to be able to go to the exactly place in the note which caused me to put the tag on.

For completeness, I do use ==mark == to highlight sections of interest, but there may be many marked sections in a note, some of which relate to specific tag, whilst other sections will not, so I would still need to scroll through the entire note looking for a section which may relate to the note. I have to almost read the whole note in its entirely every time in order to find the reason for the tag.

I hope that I have explained adequately the issues I face using tags as they stand. Tags could be an incredibly powerful tool for Joplin, if their functionality extended past just putting a label on the whole note. I suppose, I'm looking for a one-to-many relationship between a tag and a particular place in a note.

The plugin, that I was attempting to write would have resulted in me placing hidden tags in the source of the note <!-- tag:legal obligation -->. I wanted to be able to listen for a click event on the list of tags at the bottom of an individual note, and then scroll the viewing pane to the location of the matching hidden tag. Repeated clicks would take you to the next match.

If there's something that could be done with the core, I 'd be very grateful?

Thanks for clarifying, that makes sense. I'm not sure if it would make sense to expose a click handler for the tags in the status bar, because I feel there wouldn't be many use for it. I need to think about it.

Right now you could already create your own panel, list all the tags in there and attached click handler to them. That would be a second status bar with tags but it would work. What I'm wondering though is how would you scroll to the right location in the document? Is the scrollToHash command good enough for this?

I'll have to look again at scrollToHash.

The plugin that I've started creates an array of the hidden comment along with the line number that it occurs on, which is why I was asking about scrollToY? I didn't know whether this could scroll to a line number, or I'd have to calculate the Y co-ordinate (in pixels) based on the line number and font size?

It seems a bit clumsy to have to create another panel listing all the tags again considering that they are already displayed under the note, but I understand that you may wish to limit what you expose through the plugin system.

In general terms, I do feel as though tags are under utilised as they stand and any additional functionality that can easily be added would be a bonus. Thanks.

@laurent I've had another look at this and using TOC as a good place to start, I cannot get the scrollToHash to work with tags in a comment <!-- tag:tagone --> or <!-- # tag:tagone -->.

It returns an error of "cannot find hash tagone". I assume it's looking for a line starting with the hash # character?

Is there any call that could be made to scroll to a particular line number in the note?

Or how about a scroll to element id? I could use something like the following <span id="tag1">text subject of tag</span>