Check this simple demo addon:
def process_note(note: Any) -> Any: note_type = mw.col.models.by_name(note.note_type()['name']) note_type['tmpls']['afmt'] += "aaaaaaaaaaaaaaaaaaa" mw.col.models.save(note_type) hooks.note_will_flush.append(process_note)
You may think the backTemplate will have “aaaaaaaaa” when the user saves the note type But no. The change is only carried when the user DOESN’T click ‘Save’, but instead closes wihtout saving.
This is because the ‘Save’ button overrides the DB with the content of the editor.
I tried finding a hook for the ‘Save’ button, but couldn’t find any. I also tried reloading the editor to show the changes made to the DB, but couldn’t find how to get the current editor instance.
I have already spent a few hours on this. So I just want to know if it’s possible or should I find another way.