Fix preview selection in loop iteration #2182
Closed
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.
I've analyzed the VS Code Markdown Preview Enhanced extension and found the critical bug that prevents opening two markdown
files at the same time.
Root Cause
The bug is in src/preview-provider.ts at line 535. In the updateMarkdown method, there's an array indexing error:
for (let i = 0; i < previews.length; i++) {
try {
const preview = previews[0]; // BUG: Always uses index 0 instead of i
Line 535 always uses previews[0] instead of previews[i], which means when multiple previews exist, the code only ever updates
the first preview in the array, completely ignoring the others.
How This Breaks Multiple File Previews
- The loop iterates through all previews (i = 0, 1, 2...)
- But it always processes previews[0], causing it to:
Fix Plan
⏺ Fix Plan
The Problem
In src/preview-provider.ts:535, the updateMarkdown method has a critical bug where it always uses previews[0] instead of
previews[i] when iterating through multiple previews.
Changes Required
File: src/preview-provider.ts
Line 535 - Change:
const preview = previews[0]; // WRONG - always uses first preview
To:
const preview = previews[i]; // CORRECT - uses current iteration preview
Impact
This is a simple one-line fix that will:
Testing Strategy
After the fix:
Additional Notes