Fix janky scrolling in markdown preview with code blocks#287050
Merged
mjbvz merged 4 commits intoMar 26, 2026
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 was referenced Apr 4, 2026
AshtonYoon
added a commit
to AshtonYoon/vscode
that referenced
this pull request
Apr 4, 2026
Two regressions from the merge of microsoft#287050: 1. preview.ts: The merge retained `this.#isScrolling = false` inside the early-return guard of `scrollTo()`, which was intentionally removed in the original PR. This resets the timer-based flag on the very first forward-sync call, allowing subsequent editor scroll events to re-trigger forward sync while reverse sync is in progress, causing the editor to jump back up. 2. index.ts: The PR converted `onUpdateView` from a decrement-counter to a timer-based approach but left initialization and resize handlers still using `scrollDisabledCount += 1` without a corresponding timer reset. The old scroll handler decremented the counter naturally; the new handler only returns early. As a result, after page load `scrollDisabledCount` stays at 1 indefinitely, blocking all preview-to-editor sync until the user scrolls the editor once. Fixes: - Remove the erroneous `this.#isScrolling = false` from scrollTo() - Apply the same timer-reset pattern (200ms) to initialization and resize handlers so scrollDisabledCount is always auto-cleared Fixes microsoft#307762
mjbvz
added a commit
that referenced
this pull request
May 1, 2026
…l-sync-regressions markdown: fix scroll sync regressions introduced in #287050
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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