Repository navigation
markdown: stop snapping the editor back to the preview scroll position - #345112
Closed
Sundar Shahi Thakuri (sundarshahi) wants to merge 1 commit into
Closed
Sundar Shahi Thakuri (sundarshahi) wants to merge 1 commit into
Sundar Shahi Thakuri (sundarshahi) wants to merge 1 commit into
Conversation
`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 microsoft#317033
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the change making the preview-to-editor scroll handoff apply only once.
No open issues 🎉
What changed in this PR
Fixes #317033 by making the Markdown preview-to-editor scroll handoff apply only once, so later tab switches preserve the editor’s own scroll position. This complements the separate preview-side fix in #342822.
Changes:
- Remove the stored preview scroll position when it is retrieved.
- Add a regression test verifying that the position is returned once, then
undefined.
| File | Description |
|---|---|
extensions/markdown-language-features/src/test/topmostLineMonitor.test.ts |
Tests that the preview scroll position is consumed once. |
extensions/markdown-language-features/src/preview/topmostLineMonitor.ts |
Clears the stored position on retrieval to prevent repeated editor scrolling. |
Review effort: Balanced
Member
|
merged via #350010 |
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.
Fixes #317033
Motivation
After the Markdown preview of a file has been scrolled once, every later switch back to that file's text editor scrolls the editor to the preview's last position. Wherever the user had scrolled in the editor is lost on each tab switch, until the window is reloaded.
MarkdownPreviewManagerscrolls a markdown text editor toTopmostLineMonitor.getPreviousStaticEditorLineByUriwhenever it becomes active. That line is set byStaticMarkdownPreviewon every preview scroll, but unlikegetPreviousTextEditorLineByUri(the other direction), the getter never removes it. So the handoff meant for "preview → editor" is replayed on every later activation.Changes made
getPreviousStaticEditorLineByUrinow removes the entry it returns, the same waygetPreviousTextEditorLineByUridoes. Opening the text editor from a scrolled preview still lands on the preview's position once. Later tab switches keep the editor's own position.This is the editor-side half. #342822 addresses the preview-side scroll position (#147718) in
preview-src/index.tsand does not touch this code.Known limit: with a static preview open beside the text editor, the stored line is still applied once. For example, you scroll the preview without focusing it, then scroll the editor elsewhere, switch tabs and come back: the editor jumps to the preview's position one time instead of on every switch. Fully fixing that needs the stored line cleared when the user scrolls the text editor. That depends on the order of the active-editor and visible-range events when an editor opens, which I couldn't check outside the extension host, so I left it out of this PR. I can follow up with it if you want that behaviour.
How to test
Open With... > Markdown Preview) and scroll down.Validation
src/test/topmostLineMonitor.test.ts: the stored preview line is returned once, thenundefined. It fails with the change reverted (the second read returns10).tsconfig.jsontypechecks with no errors, and eslint passes on both files.vscodestub, not in the extension host.