WIP: Fix jumppiness in scroll sync when editing, especially latex
NOTE: DO NOT MERGE. This PR contains more than I intended. It should have been made on top of my other work. I'll fix it, but for now I just wanted to post this temporarily and I'll revisit it after other PRs. (I believe it should only have scrolling.ts and Editor.tsx changes.)
This fixes a nasty jumpiness in scroll syncing when editing. More specifically:
Scroll sync has to interpolate positions of latex display blocks (and other extension blocks) in the preview pane since they're not top level blocks that get tagged with data-source-line. This makes it especially bad when ...
You have some piece of latex code in the middle of the editor, and then you remove the end ']' of the latex block. This causes a chain of events, roughly: rerendering the preview pane, that latex block is now incomplete so no longer identified as a latex block, scroll sync map rebuilt, scroll sync happens, the editor gets scrolled to a new position that's far from where it was before (maybe even off screen).
The effect of this is that you delete one character and suddenly the editor scrolls to a totally new place. (To be clear, this can happen when editing non-latex as well, but it's especially bad when editing latex.)
I'm pretty sure it's never desirable for the editor to scroll as a result of editing, so...
This PR introduces a "scroll lock" while editing. It seems to do a great job of stabilizing the editor while editing, but also allows the scroll sync to continue working when you do want it.
Thanks! Probably not related but just FYI: https://github.com/mb21/panwriter/issues/95
btw. you can probably interactive rebase this branch to change it to contain only those changes. Feel free to git push --force-with-lease this branch then.