Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion docs/public/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const panels = $('panels');
// ---------------------------------------------------------------
// State
// ---------------------------------------------------------------
const STORAGE_KEY = 'gh-aw-playground-content';
let compiler = null;
let isReady = false;
let isCompiling = false;
Expand Down Expand Up @@ -175,8 +176,11 @@ function setTheme(theme) {
// ---------------------------------------------------------------
// CodeMirror: Input Editor (Markdown with YAML frontmatter)
// ---------------------------------------------------------------
const savedContent = localStorage.getItem(STORAGE_KEY);
const initialContent = savedContent || DEFAULT_CONTENT;

const editorView = new EditorView({
doc: DEFAULT_CONTENT,
doc: initialContent,
extensions: [
basicSetup,
markdown(),
Expand All @@ -189,6 +193,8 @@ const editorView = new EditorView({
}]),
EditorView.updateListener.of(update => {
if (update.docChanged) {
try { localStorage.setItem(STORAGE_KEY, update.state.doc.toString()); }
catch (_) { /* localStorage full or unavailable */ }
if (isReady) {
scheduleCompile();
} else {
Expand All @@ -200,6 +206,11 @@ const editorView = new EditorView({
parent: editorMount,
});

// If restoring saved content, clear the dropdown since it may not match any sample
if (savedContent) {
sampleSelect.value = '';
}

// ---------------------------------------------------------------
// CodeMirror: Output View (YAML, read-only)
// ---------------------------------------------------------------
Expand Down