Skip to content

markdown: stop snapping the editor back to the preview scroll position - #350010

Merged
Alexandru Dima (alexdima) merged 2 commits into
mainfrom
alexdima/reopen-345112
Nov 23, 2026
Merged

Alexandru Dima (alexdima) merged 2 commits into
mainfrom
alexdima/reopen-345112

Conversation

@alexdima

Copy link
Copy Markdown
Member

Fixes #317033. Replacement for #345112. This preserves Sundar Shahi Thakuri (@sundarshahi)'s original commit and adds only a signed merge commit that brings it up to date with main.

Summary

Since 1.120, once the Markdown preview of a file has been scrolled, every later switch back to that file's text editor scrolls the editor to the preview's last position, until the window is reloaded. #315425 made TopmostLineMonitor.getPreviousStaticEditorLineByUri stop removing the stored preview line, so the one-time handoff from the preview to the text editor was replayed every time the text editor became active.

Known limit, described in #345112: while the preview editor stays open beside the text editor, scrolling the preview can still move the text editor once, the next time the text editor becomes active.

How to test

  1. Open a long Markdown file, run Markdown: Toggle Preview (Ctrl+Shift+V, or Cmd+Shift+V on macOS) and scroll the preview down.
  2. Toggle back to the text editor. It opens at the preview's position, as before.
  3. Scroll the text editor somewhere else, switch to another tab, then switch back.
  4. The editor stays where you scrolled it. Before this change, it jumped back to the preview's position.

Validation

  • git diff origin/main...HEAD | git patch-id --stable and git show 2c785ffbcf2 | git patch-id --stable print the same patch ID (6f22a2fb574): this pull request changes exactly what markdown: stop snapping the editor back to the preview scroll position #345112 changes.
  • git diff --check origin/main...HEAD: passed.
  • Not run locally: the build and the Markdown extension tests, including the new topmostLineMonitor.test.ts. CI runs them.

🤖 Authored with GitHub Copilot on behalf of Alexandru Dima (@alexdima).

`getPreviousStaticEditorLineByUri` kept the preview's last scroll line, so
every later activation of the markdown text editor scrolled it back to that
line, overwriting where the user had scrolled. Consume the line on read, like
`getPreviousTextEditorLineByUri` does for the other direction, so the preview
to editor handoff happens once.

Fixes #317033
Brings sundarshahi's commit from #345112 up to date with main, unchanged, so that it can go through the merge queue from a branch of microsoft/vscode.

🤖 Authored with GitHub Copilot on behalf of @alexdima.

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 22:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the scroll-position handoff fix, though the build and Markdown extension tests were not run locally.

No open issues 🎉

What changed in this PR

Fixes repeated Markdown editor scroll resets by restoring the one-time handoff of the preview’s scroll position to the text editor.

Changes:

  • Removes the stored preview line after it is retrieved, preventing later tab switches from reapplying it.
  • Adds a regression test verifying that the stored line is returned once, then undefined.

No actionable findings remain. The build and Markdown extension tests were not run locally.

File Description
extensions/​markdown-language-features/​src/​test/​topmostLineMonitor.test.ts Tests one-time retrieval of the preview scroll position.
extensions/​markdown-language-features/​src/​preview/​topmostLineMonitor.ts Clears the stored preview position after retrieval.

Review effort: Balanced

@alexdima
Alexandru Dima (alexdima) added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit 2219f59 Nov 23, 2026
40 checks passed
@alexdima
Alexandru Dima (alexdima) deleted the alexdima/reopen-345112 branch November 23, 2026 23:30
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 keeps scrolling to a specific position when switching tabs

5 participants