Reset state before loading playground examples
This commit is contained in:
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user