Markdown keeps scrolling to a specific position when switching tabs
Type: Bug
- Open a markdown file in preview mode and scroll to a position
- Switch to the text editor mode for the markdown file
- Now scroll to a different position
- Switch tabs away from the markdown file and then back to the markdown file
- Expected behaviour: editor does not scroll when switching back
- Actual behaviour: editor always scrolls back to the position it was in the preview
VS Code version: Code 1.120.0 (0958016b2af9f09bb4257e0df4a95e2f90590f9f, 2026-05-12T20:17:22Z) OS version: Windows_NT x64 10.0.26200 Modes:
System Info
| Item | Value |
|---|---|
| CPUs | 13th Gen Intel(R) Core(TM) i5-1345U (12 x 2496) |
| GPU Status | 2d_canvas: enabled GPU0: VENDOR= 0x8086, DEVICE=0xa7a1 [Intel(R) Iris(R) Xe Graphics], DRIVER_VENDOR=Intel, DRIVER_VERSION=32.0.101.7084 ACTIVE GPU1: VENDOR= 0x1414, DEVICE=0x008c [Microsoft Basic Render Driver], DRIVER_VERSION=10.0.26100.8246 Machine model name: Machine model version: direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok skia_graphite: disabled_off trees_in_viz: disabled_off video_decode: enabled video_encode: enabled webgl: enabled webgl2: enabled webgpu: enabled webnn: disabled_off |
| Load (avg) | undefined |
| Memory (System) | 15.66GB (2.29GB free) |
| Process Argv | |
| Screen Reader | no |
| VM | 0% |
Extensions (35)
| Extension | Author (truncated) | Version |
|---|---|---|
| copilot-chat | Git | 0.48.1 |
| ruff | cha | 2026.42.0 |
| vscode-cylc | cyl | 1.3.0 |
| shebang-language-associator | dav | 1.4.0 |
| vscode-eslint | dba | 3.0.24 |
| gitlens | eam | 17.12.2 |
| vscode-github-actions | git | 0.31.5 |
| vscode-pull-request-github | Git | 0.144.0 |
| git-graph | mhu | 1.30.0 |
| black-formatter | ms- | 2026.4.0 |
| debugpy | ms- | 2026.6.0 |
| flake8 | ms- | 2026.6.0 |
| isort | ms- | 2026.5.11331015 |
| mypy-type-checker | ms- | 2026.4.0 |
| python | ms- | 2026.4.0 |
| vscode-pylance | ms- | 2026.2.1 |
| jupyter | ms- | 2025.9.1 |
| jupyter-keymap | ms- | 1.1.2 |
| jupyter-renderers | ms- | 1.3.0 |
| vscode-jupyter-cell-tags | ms- | 0.1.9 |
| vscode-jupyter-slideshow | ms- | 0.1.6 |
| remote-ssh | ms- | 0.122.0 |
| remote-wsl | ms- | 0.104.3 |
| powershell | ms- | 2025.4.0 |
| remote-explorer | ms- | 0.5.0 |
| remote-server | ms- | 1.5.3 |
| sqlite-viewer | qwt | 25.12.2 |
| vscode-yaml | red | 1.23.0 |
| jinjahtml | sam | 0.20.0 |
| even-better-toml | tam | 0.21.2 |
| shellcheck | tim | 0.39.5 |
| simple-rst | tro | 1.5.4 |
| explorer | vit | 1.50.4 |
| volar | Vue | 3.3.0 |
| vscode-markdown-alert | yah | 0.0.4 |
(1 theme extensions excluded)
https://github.com/user-attachments/assets/d5bc64d0-17ff-4147-9341-2305338f8d92
Same (or similar) issue haunts me for months now.
When i scroll somewhere in a markdown file and switch between the preview and edit mode with ctrl+shift+v the scroll position keeps jumping to the top of the file which is very annoying when i just wanted to check if my edit renders correctly. And sometimes when i scroll back to that position after the preview and switch between the editor/preview state again, then the scroll position keeps jumping to that frequent position instead of the top. But it's still not the scroll position where it should be (because i scrolled somewhere else before that).
Yes, I have the same issue. The scroll position in the markdown editor jumps when the focus has been in another editor pane or another tab and then the focus is returned to the markdown editor. Note that the cursor does not jump, only the scroll position. The cursor is often scrolled out of the view in fact (and moving the cursor using one of the arrow keys then of course returns the scrolling position such that the cursor is again visible). This bug occurs whether or not the markdown preview of that file is also open.
Same, still exists in 1.129.0
pasting my issue content here since it's closed as duplicated:
| Version | Behavior |
|---|---|
| 1.118.0 | Not affected — markdown.togglePreview opens the preview in a new tab (side-by-side). |
| 1.119.0 / 1.119.1 | Not affected — markdown.togglePreview now defaults to opening in the current tab, but the scroll position issue does not occur here. However, the preview always opens scrolled to the top, regardless of where the source editor was scrolled to. |
| 1.120.0 | First affected — the scroll-locking behavior described in this issue is present. |
Agent analysis suggests that:
The root cause is likely related to changes in the markdown preview's scroll state management introduced between 1.119.1 and 1.120.0.
Specifically, during that window:
preview.tsadded a#scrollToFirstDiffChangemechanism — When the preview opens, it forces a scroll to the first changed line (in diff mode). This internal#linefield is carried over when the preview is closed, and appears to be persisted into the editor's view state. If the preview scrolls to line N, then exits, the editor restores line N as its "saved" scroll position.The new
diffScrollSync.tsmodule — This manages scroll synchronization between the source editor and the rendered diff preview. When the preview closes, the last synced scroll offset from this module may be written back into the editor's state, overwriting the user's actual scroll position.
clearTimeout(this.#scrollingTimer)was added todispose()— This prevents a pending scroll-sync callback from firing during teardown. However, if the last scroll event sent from the preview (before closing) already committed a stale position to the editor, clearing the timer only prevents a potential correction, not the root issue.The core problem: When exiting preview mode (
markdown.showSourceor toggling off), the editor's view state saves the scroll position that was last synced between editor and preview — not the position the user actually scrolled to in the source editor. This saved state is then restored on tab switch, causing the "jump back" behaviour.A quick way to verify: if the scroll position is locked to the line that was at the top of the preview at exit time (rather than the editor's own scroll position), that confirms the view state is picking up the preview's last known scroll anchor instead of the editor's.
I have the same problem. It affects some files and not others. The affected files have headings down to level 4 (####). The unaffected files only go to level 2. (##) Perhaps this has something to do with the bug.
I'm having the same issue in VSCode Insiders 1.128.0 and 1.131.0. It fixes itself after reloading windows, but it's a big inconvenience
edit: Please prioritize these issues over AI support. These bugs should be prioritized for a code editor.
I've think I had one instance where closing the file and re-opening it resolved the issue. I've definitely had another example where re-opening files made no difference. Restarting vscode fixed it though.
I've just confirmed that re-opening files doesn't help but restarting VSCode fixes the problem.
Same issue here on Windows.
I can also confirm that disabling both markdown.preview.scrollEditorWithPreview
and markdown.preview.scrollPreviewWithEditor does not help — the editor
still jumps back to the locked position after switching tabs/editor groups.
A restart (or reloading the window) does fix it temporarily, but the bug comes back reliably after this sequence:
- Restart VS Code.
- Open a Markdown file and toggle the preview.
- Scroll around in the preview, then close the preview.
- Scroll the editor to a different position, then switch away and back.
The editor then jumps back to the position that was at the top of the preview when it was closed. So the scroll position gets "re-locked" every time the preview is opened and closed.
- VS Code Version: 1.132.0(改成你的版本)
- OS: Windows 11
One more observation that might narrow it down:
The bug only reproduces when there is at least one other file tab open in the window — either in the same editor group or in a floating editor window.
With only the affected Markdown file open (with or without its preview), the jump does not happen when switching back.
I noticed that the preview stays where you last reloaded the preview. If you click the three dots in the top right and click "Refresh Preview", that "saves" a new scroll location when you click back into the tab.
Are we gonna have a solution to this?
Are we gonna have a solution to this?
Are you asking VSCode dev to pause their AI development and actually improve the editor? No way. Check back in a year /s
@mjbvz is this issue planned ahead to be worked on in near future? I see some vscode's fork already fixed it so it shouldn't be hard to just copy their implementation
Version 1.137, this problem still exists
+1, issue persists even after deleting and re-creating the file. Very frustrating...
Version 1.138, this problem still exists.
Maybe related to #329625?
The issue persists, and the disorientation it causes is frustrating enough that switching to another IDE for Markdown editing seems to be an easier choice.
A fix would be greatly appreciated. An editor unexpectedly jumping to a different scroll position when switching tabs is disruptive to the editing workflow and isn't something that can reasonably be worked around.
Given how much AI driven development relies on markdown files I'm surprised this issue is not top priority. It's super disorienting to have to find the correct position in a plan.md file time and again.
Same issue. Please fix.
Same issue. Extremely annoying...