Repository navigation
Agent suggestions
Public previewDescription
Type: Bug
Description
While editing a long Markdown (.md) document and switching between it and source code files (such as .py), the Markdown editor does not preserve its scroll position.
Simply switching tabs causes the Markdown document to scroll to a different location. This behavior makes editing large documentation files difficult because the current reading/editing position is lost.
The issue occurs regardless of whether the Markdown Preview is open.
The problem does not occur with source code editors. Switching between source code files preserves the scroll position correctly. The Markdown editor should behave the same way.
Steps to Reproduce
- Open a long Markdown (
.md) file. - Scroll somewhere in the middle of the document.
- Open a source code file (for example, a Python
.pyfile). - Switch back to the Markdown tab.
Expected Behavior
The Markdown editor should preserve its exact scroll position when switching between editor tabs.
Actual Behavior
The Markdown editor scrolls to a different position after switching tabs. The amount and direction of the scroll appear inconsistent and unpredictable.
Additional Information
- The issue occurs only with the Markdown editor.
- Opening or closing the Markdown Preview does not affect the behavior.
- The problem occurs during normal editor tab switching without making any changes to the document.
- The issue is most noticeable with long Markdown documentation files.
VS Code version: Code 1.132.0 (df53daa, 2026-08-04T15:30:20Z)
OS version: Windows_NT x64 10.0.19045
Modes:
System Info
| Item | Value |
|---|---|
| CPUs | Intel(R) Xeon(R) W-2123 CPU @ 3.60GHz (8 x 3600) |
| GPU Status | 2d_canvas: enabled GPU0: VENDOR= 0x10de, DEVICE=0x1e07 [NVIDIA GeForce RTX 2080 Ti], DRIVER_VENDOR=NVIDIA, DRIVER_VERSION=32.0.15.9144 ACTIVE GPU1: VENDOR= 0x1414, DEVICE=0x008c [Microsoft Basic Render Driver], DRIVER_VERSION=10.0.19041.5794 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 webgpu: enabled webnn: disabled_off |
| Load (avg) | undefined |
| Memory (System) | 127.73GB (98.65GB free) |
| Process Argv | --crash-reporter-id 04e4fb0a-b13c-4d31-8fe3-e262850da13c |
| Screen Reader | no |
| VM | 0% |
Extensions (7)
| Name | Identifier | Author | Version |
|---|---|---|---|
| Ruff | charliermarsh.ruff | charliermarsh | 2026.68.0 |
| Blender Development | jacqueslucke.blender-development | JacquesLucke | 0.0.31 |
| Python Debugger | ms-python.debugpy | ms-python | 2026.6.0 |
| Python | ms-python.python | ms-python | 2026.4.0 |
| Pylance | ms-python.vscode-pylance | ms-python | 2026.3.1 |
| Python Environments | ms-python.vscode-python-envs | ms-python | 1.36.0 |
| YAML | redhat.vscode-yaml | redhat | 1.24.0 |
Activity
ulugbekna commentedon Aug 12, 2026
Investigation findings
I reproduced this against the reporter's exact VS Code commit,
df53daabb18cd157bdb08c7f01c34df936cf12f4, using the official Darwin arm64 build and a 2,598-line Markdown file. The underlying defect is in retained custom-editor webview layout, so it is not specific to Markdown Preview.Confirmed root cause
The Markdown custom editor is registered with
retainContextWhenHidden: true. When its tab is hidden, VS Code keeps the webview alive but its CSS-anchor-sized overlay loses the active editor anchor and falls back to the browser's default iframe dimensions, 300x150.That temporary viewport change:
#editorscroll container'sscrollTop;scrollevents;acquireVsCodeApi().setState().The Markdown webview's
document.visibilityStateremainsvisibleduring this CSSvisibility: hiddentransition, so itsvisibilitychangehandling does not detect ordinary editor-tab switching. Scroll restoration only runs when the webview document is created, not when a retained webview is revealed.Relevant code:
retainContextWhenHidden: trueOverlayWebview.release()retaining a hidden webviewanchor-size(width/height)overlay sizingMeasurements from the exact build
I set
scrollTop = 12000, switched from the Markdown custom editor to a TypeScript editor in the same group, then switched back:scrollTopFor this static document on macOS, Chromium eventually reversed the reflow and returned to the original offset. However, VS Code first exposed the webview while its inner document was still at the wrong size and position, producing the visible jump. The amount varies with scroll location and document wrapping, matching the reported inconsistent behavior. Dynamic layout, timing, and the Windows focus path can make the transient value persist.
Causal validation
As a control, I froze the retained overlay at its last active 844x675 size while hidden. Across the same tab switch:
scrollTopstayed exactly 12,000;This confirms the hidden 300x150 reflow is the primary cause.
Related core issue
This is the scroll-state consequence of:
#326482 addresses revealing a retained iframe before a connected anchor is bound. Its regression coverage should inspect the inner webview viewport and scroll state, not only the outer iframe rectangle: in this trace the outer iframe was already 844x675 while the inner document was still laid out at 300x150.
Recommended fix
webviewPanel.visible, suppress persistence of layout-induced scroll events while hidden/revealing, and restore the last stable visible position after dimensions settle.scrollTopremain unchanged.There may also be a secondary Windows-specific focus contribution related to #324758: VS Code restores webview focus through
contentWindow.focus(), while directly focusing the large EditContext-bearing Markdown root withoutpreventScrollcan move a native scroll container. The 300x150 reflow above is directly confirmed; the focus contribution still needs an isolated Windows run.