[Addon dev] After changing `note.fields`, how can I ensure the changes to appear on editor web?

I’m the developer of Cloze (Hide All) addon. Recently I got a bug regarding the degraded performance of Anki cause of my addon. After profiling I found that this code was the culprit.

Basically, on every saveNow the addon transforms HTML segments via Python code, do self.note.flush(). self.mw.requireReset() tries to copy the updated HTML code to web. I think this is necessary as the addon should coexist with other supposed addons which expects web content to match the python fields.

self.mw.requireReset() takes too long, so I wanna know if there’s a faster way to sync editor.note.fields back to the editor.web.

Alternatively, I can move all the processing code to JS side, but this would incur several other issues like my JS code should be able to access all Svelte-created contenteditable divs by index. (Which I don’t know how)

Thanks.

1 Like

Did you try using the note_will_flush hook instead? Then you don’t have to do a reset.

2 Likes

It works. It seems like for editor opened during review, the callback won’t be called until the editor exits. So the addons do not properly transform the live-viewed edits on the reviewer. I think I can handle this case separately. Thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.