obynio / anki-japanese-furigana

Anki add-on providing support for adding furigana on Japanese text
https://ankiweb.net/shared/info/678316993
GNU General Public License v3.0
17 stars 5 forks source link

Add Anki 2.1.50+ support and fix a couple bugs #11

Closed ahlec closed 1 year ago

ahlec commented 1 year ago

Hi!

Huge caveat that I'm not a Python developer, and this is my first time working with Anki, so please be welcome to suggest any changes, big or small!

Anki 2.1.50 released further refactors to the editor interface, which broke this plugin (and many others like it). In particular, it appears that getCurrentField was removed from the runtime, which mean that trying to find the HTML for the current field was producing an infinite loop (the JS was erroring, and the callback was then called with elements=None, which would call the JS again).

I spent a long time trying to figure out what the new best solution was, but wasn't able to really get a good sense from looking through the Anki PRs what would directly replace the removal of getCurrentField. In lieu of that, I opted to use the note and currentField fields on the Editor object. However, these has been around for a couple of years now, so I'm not sure if there's a particular reason not to use them. Any tips here would be appreciated!

Additional Changes

Additionally, I made a couple of changes as I was working. If you'd prefer I separate them into other PRs for better tracking/visibility, I'm happy to do so!

obynio commented 1 year ago

Awesome work ! I'll review that as soon as possible !

obynio commented 1 year ago

When I started working on this module, I also had to find a way to support users on newer version with breaking changes while handling users on older versions. These Anki deprecations are really a struggle to deal with.

obynio commented 1 year ago

Thank you for your great work, I just released the change on the Anki package manager, feel free to check it out !