glutanimate / frozen-fields

A fork of Tiago Barroso's Frozen Fields add-on with support for Anki 2.1
https://ankiweb.net/shared/info/516643804
Other
24 stars 4 forks source link

Anki 2.1: Hook loadNote instead of replacing it entirely #5

Closed tsudoko closed 4 years ago

tsudoko commented 6 years ago

It's more compatible with other addons and less prone to breakage in case aqt.editor.Editor.loadNote gets changed.

Fixes compatibility with the Add note id addon, which didn't work previously with this addon installed.

glutanimate commented 6 years ago

Hi tsudoku,

Thanks for the contribution! This definitely looks promising. I was never a fan of how FF had to overwrite loadNote in its entirety.

The main issue I'm seeing is that adding the elements after the note has been loaded causes the fields to shift around momentarily This happens whenever the field state is toggled which makes it rather hard to ignore.

If you could perhaps find a way to fix that I'd merge the PR in a heartbeat.

tsudoko commented 6 years ago

I'm not sure if it's possible to prevent that without somehow editing the original setFields JS function or copying the whole thing and replacing it like the original did, so I've decided to just avoid calling loadNote after the field is toggled.

There's a similar problem when you edit field HTML (ctrl+shift+x) and close the HTML editor window. If you think replacing setFields entirely with an edited copy of the original function is a better idea, I can do that. I personally don't mind the flickering as long as it doesn't happen every time I freeze a field.

The HTML page for the editor is made when Editor.setupWeb calls stdHtml, but that also loads the page, so it's not even possible to edit setFields in some hacky way (re.sub?) without reloading the whole page.


The codebases for Anki 2.0 and 2.1 have diverged so much at this point it might be a better idea to put them into separate files. What do you think? I deliberately avoided changing the 2.0 parts because I don't use 2.0 anymore, the 2.0 version of the addon worked fine for me without any compatibility issues, and changing anything might introduce new unwanted problems which seems like too much effort for little gain for a legacy version.

tsudoko commented 6 years ago

Looks like the buttons get duplicated when you switch the note type in the editor. I'll look into it, it might be possible I shouldn't have addressed the issue you brought up the way I did.

glutanimate commented 4 years ago

@tsudoko I've just merged Arthur's PR in #15 which implements a similar solution that seems to solve the issues we discussed in here. Thanks again for spearheading this effort!