Fix: Scroll markdown preview to top when navigating to new document #290101
+2
−0
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