atom-community / markdown-preview-plus

Markdown Preview + Community Features
https://atom.io/packages/markdown-preview-plus
Other
370 stars 85 forks source link

"number equations" option results in preview scrolling back after rerender #496

Open JackElsey opened 4 years ago

JackElsey commented 4 years ago

example.zip

Reproduction steps:

  1. Uncheck all three options under "preview position synchronization behavior".
  2. Check "number equations" under "math options".
  3. Render example.md and scroll preview to bottom.
  4. On line 243 of the source, repeatedly add and remove two new lines before the last sentence ("Donec vestibulum non...").

The preview window should eventually scroll to the beginning of the document.

I thought this issue was related to #106 but the same behavior happens if using the markdown-it renderer backend. I shouldn't have had the "number equations" option enabled because I am not using pandoc-crossref.

lierdakil commented 4 years ago

Thanks for the report.

This proved to be a somewhat complicated issue, confounded by multiple smaller issues. I'll try to not bore you with the details, but for posterity, some primary components:

Anyway, I did some work towards fixing or at least mitigating some of those, but I'm running out of time I can dedicate to this for now, so I'm pushing out a slightly half-baked release v4.4.0. See the changelog for detailed release notes. Please report any bugs/issues you encounter, I'll try to fix what I can.

Side note, detecting insertions efficiently proved to be a rather difficult problem. The naive approach at best has quadratic complexity, which makes it rather impractical for pseudo-realtime applications, and even the more advanced algorithms are superlinear. For now, I settled on a variation on Myers' diff (Myers, Eugene W. "An O(ND) difference algorithm and its variations." Algorithmica 1, no. 1-4 (1986): 251-266.), but it can still be noticeably slow on larger documents, so by default it's not enabled. A simple heuristic algorithm with linear complexity that handles only insertions or only deletions is used by default instead. Should be good enough for common cases, but some weirdness is bound to happen in the edge cases. Advice is welcome, if you happen to have any.

JackElsey commented 4 years ago

I don't have any algorithm suggestions, but maybe you could just make the warning under the "number equations" setting a bit more explicit for the time being?

Thank you for putting so much work into this repo and for being so responsive to these issues. I have tipped your GitHub account 150 Basic Attention Tokens (current value of $40). Claim them here... they should show up in your account after a couple days.

lierdakil commented 4 years ago

make the warning under the "number equations" setting a bit more explicit

The issue isn't actually predicated on "number equations" being enabled -- it's just exacerbated. So a warning would have questionable efficacy. I'll think about rewording what's there though, since currently it's a bit too vague. Thanks for pointing it out.

Thank you for putting so much work into this repo and for being so responsive to these issues

I'll be honest, you just happened to catch me when I'm not insanely busy with my day job. Generally, I'm not this quick to take action. I try though.

I have tipped your GitHub account

Thank you for your generosity.