Reset state before loading playground examples

This commit is contained in:
2026-07-09 19:27:19 +09:00
parent 43f692e75c
commit 1080081cec
+5 -4
View File
@@ -137,11 +137,13 @@ function saveProject() {
function loadExampleProject(exampleId) { function loadExampleProject(exampleId) {
const example = playgroundExamples.find((item) => item.id === exampleId) ?? starterProject; const example = playgroundExamples.find((item) => item.id === exampleId) ?? starterProject;
project.files = cloneFiles(example.files); const files = cloneFiles(example.files);
project.activePath = example.activePath; project.files = {};
project.activePath = '';
project.entryPath = example.entryPath ?? example.activePath; project.entryPath = example.entryPath ?? example.activePath;
project.files = files;
exampleSelect.value = example.id; exampleSelect.value = example.id;
setActiveFile(project.activePath); setActiveFile(example.activePath);
output.textContent = ''; output.textContent = '';
output.classList.remove('error'); output.classList.remove('error');
execute(); execute();
@@ -304,7 +306,6 @@ formatButton.addEventListener('click', formatActiveFile);
loadExample.addEventListener('click', () => { loadExample.addEventListener('click', () => {
const example = playgroundExamples.find((item) => item.id === exampleSelect.value); const example = playgroundExamples.find((item) => item.id === exampleSelect.value);
if (!example) return; if (!example) return;
if (!confirm(`Load example "${example.title}"? This replaces the current virtual files.`)) return;
loadExampleProject(example.id); loadExampleProject(example.id);
}); });
newFile.addEventListener('click', () => { newFile.addEventListener('click', () => {