Fix: Scroll markdown preview to top when navigating to new document - #290101
Closed
Shubham (shubham21155102) wants to merge 3 commits into
Closed
Fix: Scroll markdown preview to top when navigating to new document#290101Shubham (shubham21155102) wants to merge 3 commits into
Shubham (shubham21155102) wants to merge 3 commits into
Conversation
Issue: Fixes microsoft#164071 Problem: When clicking a relative link in a markdown preview to navigate to another markdown document, the new document would open at the same scroll position as the previous document instead of scrolling to the top. This created a confusing user experience where users would see the middle or bottom of the new document without any context. Root Cause: The markdown preview webview was preserving the scroll position when updating content for a different markdown resource. When the 'updateContent' message was received with a new resource (data.source !== documentResource), the code would replace the body content but did not reset the scroll position. Solution: Added window.scrollTo(0, 0) call immediately after replacing the document body when navigating to a different markdown resource. This ensures that when a user clicks a relative link to another markdown file, the preview scrolls to the top of the new document, providing the expected navigation behavior. Changes: - extensions/markdown-language-features/preview-src/index.ts: Added scroll reset when navigating to different documents in the 'updateContent' message handler Testing: The fix can be manually tested by: 1. Creating two markdown documents with enough content to scroll 2. Adding a relative link from one document to the other 3. Opening the first document in markdown preview 4. Scrolling down and clicking the link 5. Verifying the second document opens at the top (not at the previous scroll position) Contributor: shubham21155102 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copilot started reviewing on behalf of
Shubham (shubham21155102)
January 24, 2026 06:14
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes a navigation bug in the markdown preview where clicking a relative link to navigate to another markdown document would maintain the previous document's scroll position instead of scrolling to the top of the new document.
Changes:
- Added a scroll reset to top when the markdown preview webview switches to display a different document
Collaborator
|
Superseded by #333464 |
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.
Issue: Fixes #164071
Problem:
When clicking a relative link in a markdown preview to navigate to another markdown document, the new document would open at the same scroll position as the previous document instead of scrolling to the top. This created a confusing user experience where users would see the middle or bottom of the new document without any context.
Root Cause:
The markdown preview webview was preserving the scroll position when updating content for a different markdown resource. When the 'updateContent' message was received with a new resource (data.source !== documentResource), the code would replace the body content but did not reset the scroll position.
Solution:
Added window.scrollTo(0, 0) call immediately after replacing the document body when navigating to a different markdown resource. This ensures that when a user clicks a relative link to another markdown file, the preview scrolls to the top of the new document, providing the expected navigation behavior.
Changes:
Testing:
The fix can be manually tested by:
Contributor: shubham21155102