zhaoshenzhai / obsidian-mathlinks

An Obsidian.md plugin to render MathJax in your links.
MIT License
60 stars 4 forks source link

Bugfix & improvement for the API update() function #59

Closed RyotaUshio closed 1 year ago

RyotaUshio commented 1 year ago
  1. When called with file: TFile, the update() function now dispatches a transaction only for a markdown view whose file links to the specified TFile.

  2. It turned out that the previous implementation made it impossible for the update() API function call to dispatch forceUpdateEffect properly. This was because forceUpdateEffect was defined like this:

https://github.com/zhaoshenzhai/obsidian-mathlinks/blob/8869a1df04cdcd28c1c9376b7d156187d6a45b31/src/links/preview.ts#L60

This is not problematic at all for MathLinks itself, but for another plugin using the API, this creates a different forceUpdateEffect in its main.js as a result of bundling. As a result, this plugin dispatches forceUpdateEffect that is different from the original one, and this new state effect has no effect on the decorations MathLinks creates.

I fixed this by making forceUpdateEffect a member property of the MathLinks plugin instance. This way, we can always reference to the same forceUpdateEffect instance.

https://github.com/zhaoshenzhai/obsidian-mathlinks/blob/cc7ef76939563ea1f9dfcb20ce32589045a99d62/src/main.ts#L17

RyotaUshio commented 1 year ago

Hey @zhaoshenzhai, I've just rolled out version 0.5.1. Could you update the npm package when it's convenient for you? Appreciate it!