Skip to content

Conversation

@shubham21155102
Copy link

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:

  • 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

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 AI review requested due to automatic review settings January 24, 2026 06:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown preview does not scroll to top on new URI

2 participants