Add source map for every block-level element in the Markdown preview #133376
Labels
bug
Issue identified by VS Code Team member as probable bug
help wanted
Issues identified as good community contribution opportunities
insiders-released
Patch has been released in VS Code Insiders
markdown
Markdown support issues
verified
Verification succeeded
Milestone
Issue Type: Bug
Does this issue occur when all extensions are disabled?: Yes
1.61.0-insider (system setup)
(a0af581)Windows_NT x64 10.0.19043
I searched the Issues by https://github.com/microsoft/vscode/issues?q=is%3Aissue+label%3Amarkdown+scroll, found some cases with similar behavior, but couldn't recognize one as the same. So, I open this issue in case a root cause of bugs has't been revealed.
Steps to Reproduce
Create a Markdown editor, and fill it with one of the samples below.
Adjust the window size, so that no more than 30 lines are visible in the editor.
"Open Preview to the Side".
Scroll the preview.
Actual behavior:
The editor is scrolled strangely, or jumps to an unexpected position, or whatever.
Expected behavior:
The editor and the preview should be synchronized, all or most of the time.
Problem
The Markdown preview only sets source map for a few kinds of elements, which can lead to severely inaccurate scrolling:
vscode/extensions/markdown-language-features/src/markdownEngine.ts
Lines 114 to 116 in a0af581
It can be observed in many conditions, such as:
Scrolling the preview in order to find something in the editor.
Editing a long document when the preview is open.
Solution
Add source map for every element where possible.
Here is a solution. I've tested it by adding a Markdown extension.
First, internally create a markdown-it plugin in the
markdownEngine.ts
:Then, load it just before the
return
:Known limitations:
Some markdown-it plugins do not respect
attrs
, thus, their output won't get source map.Sample 1
Repeat this piece 10 times:
Sample 2
Begin the document with:
#
Then, add 99 blank lines.
Next, add:
Finally, repeat this line 99 times:
The text was updated successfully, but these errors were encountered: