Skip to content

Commit 41e3b36

Browse files
committed
fix(mdviewer): preserve edit mode and cache across panel hide/show
- Use persistent _mdIframeRef in MarkdownSync to detect iframe reuse across deactivate/activate cycles - Move reloadCurrentFile() to reload button handler only, preventing cache clear on panel show - Fix edit mode preservation: global edit mode survives panel toggle
1 parent 66827af commit 41e3b36

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ define(function (require, exports, module) {
3030
let _active = false;
3131
let _doc = null;
3232
let _$iframe = null;
33+
let _mdIframeRef = null; // persistent reference to the md iframe DOM element, survives deactivate
3334
let _baseURL = "";
3435
let _syncId = 0;
3536
let _lastReceivedSyncId = -1;
@@ -57,17 +58,18 @@ define(function (require, exports, module) {
5758
* @param {string} baseURL - Base URL for resolving relative image/resource paths
5859
*/
5960
function activate(doc, $iframe, baseURL) {
60-
const sameIframe = _$iframe && $iframe && _$iframe[0] === $iframe[0];
61-
6261
if (_active) {
6362
deactivate();
6463
}
6564

6665
_doc = doc;
66+
// Check if this is the same iframe we've used before (persistent md iframe)
67+
const reusingIframe = _mdIframeRef && $iframe[0] === _mdIframeRef;
6768
_$iframe = $iframe;
69+
_mdIframeRef = $iframe[0];
6870
_baseURL = baseURL;
6971
_active = true;
70-
_iframeReady = sameIframe; // If reusing iframe, it's already ready
72+
_iframeReady = reusingIframe;
7173
_syncId = 0;
7274
_lastReceivedSyncId = -1;
7375

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,9 @@ define(function (require, exports, module) {
840840
$pinUrlBtn.click(_togglePinUrl);
841841
$livePreviewPopBtn.click(_popoutLivePreview);
842842
$reloadBtn.click(()=>{
843+
if (_isMdviewrActive) {
844+
MarkdownSync.reloadCurrentFile();
845+
}
843846
_loadPreview(true, true);
844847
Metrics.countEvent(Metrics.EVENT_TYPE.LIVE_PREVIEW, "reloadBtn", "click");
845848
});
@@ -867,10 +870,6 @@ define(function (require, exports, module) {
867870

868871
if (_isMdviewrActive) {
869872
// Mdviewr iframe already loaded, just update the sync for the new document
870-
if (force) {
871-
// Reload: clear this file's cache and force re-render
872-
MarkdownSync.reloadCurrentFile();
873-
}
874873
MarkdownSync.activate(currentDoc, $iframe, baseURL);
875874
return;
876875
}

0 commit comments

Comments
 (0)