Skip to content

Commit 4c1449b

Browse files
committed
fix: pinned md preview switches when opening another file
When md viewer is pinned and user switches to another md or HTML file, the preview would switch instead of staying pinned. Two fixes: - _loadMdviewrPreview: check urlPinned before activating MarkdownSync on a new document when md viewer is already active - _activeDocChanged: skip openLivePreview when md viewer is pinned to prevent HTML LP iframe from replacing the pinned md viewer Update pin test to cover md→HTML and md→md switches with negative assertions verifying the pinned preview stays visible.
1 parent e4131b4 commit 4c1449b

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

src/extensionsIntegrated/Phoenix-live-preview/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,10 @@ define(function (require, exports, module) {
876876
_setTitle(relativeOrFullPath, currentPreviewFile, "");
877877

878878
if (_isMdviewrActive) {
879+
if (urlPinned && !force) {
880+
// Pinned — don't switch the md viewer content
881+
return;
882+
}
879883
// Mdviewr iframe already loaded, just update the sync for the new document
880884
MarkdownSync.activate(currentDoc, $iframe, baseURL);
881885
return;
@@ -1160,6 +1164,10 @@ define(function (require, exports, module) {
11601164
}
11611165

11621166
function _activeDocChanged(event, focusedEditor, lostEditor) {
1167+
// When md viewer is pinned, don't open HTML live preview — keep the md viewer visible
1168+
if (_isMdviewrActive && urlPinned) {
1169+
return;
1170+
}
11631171
if(!LivePreviewSettings.isUsingCustomServer() && !LiveDevelopment.isActive()
11641172
&& (panel.isVisible() || StaticServer.hasActiveLivePreviews())) {
11651173
// we do this only once after project switch if live preview for a doc is not active.

test/spec/LiveDevelopmentMultiBrowser-test.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,20 +1764,36 @@ define(function (require, exports, module) {
17641764

17651765
await waitsForLiveDevelopmentToOpen();
17661766
await awaitsForDone(SpecRunnerUtils.openProjectFiles([`readme.md`]),
1767-
"SpecRunnerUtils.openProjectFiles simple1.html");
1767+
"SpecRunnerUtils.openProjectFiles readme.md");
17681768

17691769
await _waitForIframeSrc(`readme.md`);
17701770
let pinURLBtn = testWindow.$(testWindow.document.getElementById("pinURLButton"));
17711771
pinURLBtn.click();
17721772

1773+
// Pin active on readme.md — switch to SVG, md viewer should stay
17731774
await awaitsForDone(SpecRunnerUtils.openProjectFiles([SVG_IMAGE_PATH]),
17741775
SVG_IMAGE_PATH);
1775-
await awaits(500);
17761776
await _waitForIframeSrc(`readme.md`);
17771777

1778-
pinURLBtn.click();
1778+
// Switch to HTML file while md is pinned
1779+
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["simple1.html"]),
1780+
"open simple1.html while md pinned");
1781+
// Negative assertion: wait for async switch to settle, then verify it did NOT happen
1782+
await awaits(500);
1783+
let mdIFrame = _getMdPreviewIFrame();
1784+
expect(mdIFrame && mdIFrame.style.display !== "none").toBeTrue();
17791785

1780-
await _waitForIframeSrc(SVG_IMAGE_PATH);
1786+
// Switch to another md file while md is pinned
1787+
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["sample.md"]),
1788+
"open sample.md while md pinned");
1789+
// Negative assertion: wait for async switch to settle, then verify it did NOT happen
1790+
await awaits(500);
1791+
mdIFrame = _getMdPreviewIFrame();
1792+
expect(mdIFrame && mdIFrame.style.display !== "none").toBeTrue();
1793+
1794+
// Unpin — should switch to current file (sample.md)
1795+
pinURLBtn.click();
1796+
await _waitForIframeSrc(`sample.md`);
17811797

17821798
await endPreviewSession();
17831799
}, 30000);

0 commit comments

Comments
 (0)