Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force to run Marp script before VS Code preview script #252

Merged
merged 4 commits into from
Jun 19, 2021

Conversation

yhatt
Copy link
Member

@yhatt yhatt commented Jun 15, 2021

For keeping extension sustainabillity, Marp for VS Code has not any scroll-sync logic and relies to VS Code's built-in preview script. Scroll sync is working correctly in almost cases, but sometimes the preview pane brings unexpected scroll when updated webview by editing.

When updating preview, VS Code is trying to restore the previous scroll position by calling scrollTo on loading. A timing of execution this script is same as other extensions contributed scripts included Marp. However, they will run in unpredictable order because they are injected through <script async>. If VS Code ran built-in initialization script before Marp's preview script, a calculated scroll position for stabilization would be wrong due to its styles are based on what have not applied Marp specific styles. On the other hand, the built-in scroll stabilization will work to Marp slides perfectly if ran Marp preview script before built-in script. This is reason why user occasionally see to unexpected scroll.

-- #251

This PR takes different approach from #251: Patch MarkdownContentProvider.prototype.getScripts to force running Marp's preview script before other scripts including VS Code preview.

VS Code's Markdown extension has become able to patch because the engine has exposed to env object of markdown-it renderer since VS Code v1.57 (https://github.com/microsoft/vscode/blob/b0ae2854927c19e4de54edd3890ec681f96476e5/extensions/markdown-language-features/src/markdownEngine.ts#L166-L175). It is obviously a hack but removing async attribute from Marp <script> is the most reliable way to prevent jumping scroll.

Fix #248.

@yhatt yhatt merged commit 602dd7f into main Jun 19, 2021
@yhatt yhatt deleted the force-running-marp-script-before-vscode-2 branch June 19, 2021 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The previewed slide page keeps jumpping when I edit the markdown document
1 participant