Fix janky scrolling in markdown preview with code blocks#287050
Merged
mjbvz merged 4 commits intomicrosoft:mainfrom Mar 26, 2026
Merged
Fix janky scrolling in markdown preview with code blocks#287050mjbvz merged 4 commits intomicrosoft:mainfrom
mjbvz merged 4 commits intomicrosoft:mainfrom
Conversation
Fixes microsoft#278930 This commit fixes the scroll synchronization issues between the markdown editor and preview when scrolling through code blocks: 1. **Code block line tracking**: Added endLine calculation for fenced code blocks by counting newlines, enabling accurate line-to-position mapping within multi-line code blocks. 2. **Padding-aware scrolling**: Implemented getContentBounds() to calculate scroll positions excluding padding, preventing jumps when scrolling through code blocks with padding. 3. **Scroll loop prevention**: Changed scroll disable flags from counters to timer-based booleans (50ms) to prevent infinite sync loops while maintaining smooth bidirectional synchronization. The fix ensures smooth scrolling through code blocks without jumping or stuttering in both directions (editor ↔ preview).
Contributor
Author
|
@microsoft-github-policy-service agree |
Contributor
|
can confirm it fixes the scroll resetting issue |
|
I can also confirm that this fixes the issue. |
|
When will it be merged if everything is ok? |
DonJayamanne
approved these changes
Mar 26, 2026
Yoyokrazy
approved these changes
Mar 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #278930
Summary
This PR fixes the scroll synchronization issues between the markdown editor and preview when scrolling through code blocks. Previously, scrolling through code blocks would cause noticeable jumps and stuttering due to:
Changes
1. Code block line tracking (
scroll-sync.ts)endLinecalculation for fenced code blocks by counting newlinesCodeLineElementto include optionalendLineproperty2. Padding-aware scrolling (
scroll-sync.ts)getContentBounds()function to calculate content area excluding padding3. Scroll loop prevention
index.ts): ChangedscrollDisabledCountto use timer-based reset (50ms)preview.ts): Changed_isScrollingfrom counter to timer-based boolean (50ms)Result
Smooth scrolling through code blocks without any jumping or stuttering in both directions.
As-Is
Screen.Recording.2026-01-12.at.10.24.48.AM.mov
To-Be
Screen.Recording.2026-01-12.at.10.25.48.AM.mov