jdlorimer / incremental-reading

Anki add-on providing incremental reading features
https://ankiweb.net/shared/info/935264945
ISC License
216 stars 38 forks source link

Make sure to store original bridge and fall back on it when appropriate #101

Closed glutanimate closed 4 years ago

glutanimate commented 4 years ago

Hi luoliyan,

I noticed that some add-ons like Pop-up Dictionary or Edit Field During Reviews that depend on a custom link handler would stop working as soon as the first IR card appeared. It seems like this is because IR currently irreversibly overwrites mw.web.onBridgeCmd.

This commit introduces a quick and dirty change that let's IR keep track of the original onBridgeCmd and makes it fall back to it when appropriate. I've only done some preliminary testing, but it seems like all pertinent features like storing the page scroll position and zoom level still work well after this patch. And the add-ons mentioned above now work without any issues both when displaying IR cards and regular Anki cards.

(The implementation is not that beautiful, so please feel free to switch to a different approach at any point)

Thanks again for all your work on this project!

P.S.: This PR is part of an effort to curb common add-on conflicts in web views. Please see the other PRs referenced at the bottom here for more information on this

jdlorimer commented 4 years ago

Thanks.

I was never entirely comfortable with the onBridgeCmd monkey patch approach, but even after discussing with Damien I couldn't see a "smart" way to achieve what needs to be achieved.

Your change doesn't seem problematic, so I'll merge it as is, with the caveat that I've basically forgotten how most of this add-on works after being a very slack maintainer the past year.

glutanimate commented 4 years ago

Thanks! Yeah, same feelings here about the onBridgeCmd / link handler system. Hopefully we can find a better way to facilitate the JS<->Python bridge for add-ons at some point.