Closed bojjenclon closed 5 years ago
Hello, this might be confusing, but runOnNoteChange is triggered on backend so it might not do what you expect. Actually most of these events are backend only, runOnNoteView is kind of an exception because it was meant to modify/inject content of the note view.
Can I ask what was your intention with runOnNoteChange on the frontend?
Ah, interesting. I wrote a code node (well technically two) that creates a statusbar, with a word count widget on it. I wanted to detect changes to the note so I could recalculate the current word count, and figured that would be the correct event.
Example of what I'm trying to accomplish.
That looks pretty nice! I will think about this, this looks like a valid use case which I hadn't thought of.
Thanks! In the mean time I suppose I'll see if I can hook into some other type of event like DOMSubtreeModified I suppose. Great work on this app by the way!
Hello, I added runOnNoteChange firing on the frontend as well. Just make sure to have your script in "JavaScript frontend" note as opposed to "JavaScript backend" - that's how Trilium knows whether to execute such note for runOnNoteChange event on frontend or backend. I'll probably follow this pattern with other events as well.
This event is fired after the note is auto-saved so when continuously typing it should be triggered every ~3 seconds.
This will be in the soon to be released 0.28.1-beta.
Great work! The timing is slightly slow for a word count feature (my original use case) so I think I'll stick with the MutationObserver approach I came up with in the mean time, but this will certainly be useful for other scripts.
@bojjenclon . I was trying to do this same thing. Care to share a link of the script note you made?
Word count added as an example of custom widget. However, note that this will work only with not yet released version 0.42.8.
Unless I'm misunderstanding the intent of the event, the runOnNoteChange relation never seems to fire for my notes when I change text within them. I know the code node attached to it works, as I have the same node bound to runOnNoteView and that works fine.