Skip to content

Agent Zero AI framework

Skip hidden Markdown previews when opening source files

Alessandroe46242fd3ee9
diff --git a/plugins/_editor/AGENTS.md b/plugins/_editor/AGENTS.md
index 55869cc7a..623db7aeb 100644
--- a/plugins/_editor/AGENTS.md
+++ b/plugins/_editor/AGENTS.md
@@ -17,6 +17,7 @@
- This always-enabled plugin is the sole file-editing UI; Files Edit and New file route here. The retired `modals/file-editor` UI is removed.
- Ctrl+F in source mode belongs to ACE; the preview search handles only preview mode and closes when returning to source.
- Source mode uses ACE line numbers and its bundled filename-to-language mapping; JSONL uses JSON highlighting. Preview and formatting controls remain available only for Markdown/plain text.
+- Render Markdown preview only while a previewable document is in preview mode; hidden preview bindings must not parse source text.
- Inherit text size, binary detection, and UTF-8 validation from `helpers.file_browser.FileBrowser` (10 MiB by default, configurable in File Browser settings). Files supplies frontend limits through its directory API. Retain save-conflict protection and provider permissions. Authenticated Files opens, creation, Rename, and Save As retain File Browser filesystem access; agent artifact paths remain scoped.
- Tool-result refreshes update already-open code files as well as Markdown, preserving dirty tabs and the existing explicit Markdown handoff policy.
- Remote `/@connections/` documents use `file_browser_connections` process-local sessions and permission-checked provider saves through the shared Editor. Keep remote requests out of local document-store/WebSocket paths; preserve dirty text on failed or conflicting saves. Remote Save As retargets the returned session ID.
diff --git a/plugins/_editor/webui/editor-store.js b/plugins/_editor/webui/editor-store.js
index 6d210b7fd..72555c038 100644
--- a/plugins/_editor/webui/editor-store.js
+++ b/plugins/_editor/webui/editor-store.js
@@ -402,7 +402,7 @@ const model = {
},
previewHtml() {
- if (!this.isTextDocument()) return "";
+ if (!this.canPreview() || !this.isPreviewMode()) return "";
return renderEditorPreviewMarkdown(this.currentPage().markdown || "", this.editorText);
},
diff --git a/tests/test_editor_files.py b/tests/test_editor_files.py
index 55b67b8b9..2a22d904a 100644
--- a/tests/test_editor_files.py
+++ b/tests/test_editor_files.py
@@ -62,6 +62,23 @@ const editorStore = (() => {
''' + editor + r'''
return store;
})();
+let previewRenders = 0;
+const buildMarkdownPages = text => [{ markdown: text }];
+const renderEditorPreviewMarkdown = text => { previewRenders++; return text; };
+for (const extension of ['json', 'py', 'md', 'txt']) {
+ editorStore.session = { session_id: 'preview-check', extension };
+ editorStore.editorText = 'initial text';
+ editorStore.viewMode = 'source';
+ assert.equal(editorStore.previewHtml(), '', 'source mode must not build a hidden preview');
+ editorStore.viewMode = 'preview';
+ assert.equal(editorStore.previewHtml(), ['md', 'txt'].includes(extension) ? 'initial text' : '');
+ editorStore.viewMode = 'source';
+ editorStore.editorText = 'changed text';
+ assert.equal(editorStore.previewHtml(), '');
+ editorStore.viewMode = 'preview';
+ assert.equal(editorStore.previewHtml(), ['md', 'txt'].includes(extension) ? 'changed text' : '');
+}
+assert.equal(previewRenders, 4, 'render only visible previews, using current source text');
const tab = { tab_id: 'tab', session_id: 'session', path: '/a0/test.py', extension: 'py', text: 'unsaved', dirty: true };
editorStore.tabs = [tab];
editorStore.session = tab;