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) {
const example = playgroundExamples.find((item) => item.id === exampleId) ?? starterProject;
project.files = cloneFiles(example.files);
project.activePath = example.activePath;
const files = cloneFiles(example.files);
project.files = {};
project.activePath = '';
project.entryPath = example.entryPath ?? example.activePath;
project.files = files;
exampleSelect.value = example.id;
setActiveFile(project.activePath);
setActiveFile(example.activePath);
output.textContent = '';
output.classList.remove('error');
execute();
@@ -304,7 +306,6 @@ formatButton.addEventListener('click', formatActiveFile);
loadExample.addEventListener('click', () => {
const example = playgroundExamples.find((item) => item.id === exampleSelect.value);
if (!example) return;
if (!confirm(`Load example "${example.title}"? This replaces the current virtual files.`)) return;
loadExampleProject(example.id);
});
newFile.addEventListener('click', () => {