feat(app): pass codePrefix/codeSuffix to editor on lesson load

- Update loadCurrentLesson() to pass prefix/suffix to editor
- Use getEditableValue() in runCode() to get only user code
This commit is contained in:
2026-01-25 02:00:07 +01:00
parent 3a1c0a36f9
commit 8ed6a908a8

View File

@@ -653,8 +653,11 @@ function loadCurrentLesson() {
renderDifficultyBadge(elements.lessonTitleRow, lesson); renderDifficultyBadge(elements.lessonTitleRow, lesson);
// Set user code in CodeMirror (clear history to prevent undo/redo across lessons) // Set user code in CodeMirror (clear history to prevent undo/redo across lessons)
// Pass codePrefix/codeSuffix as read-only zones for CSS mode
if (codeEditor) { if (codeEditor) {
codeEditor.setValueAndClearHistory(engineState.userCode); const prefix = lesson.codePrefix || "";
const suffix = lesson.codeSuffix || "";
codeEditor.setValueAndClearHistory(engineState.userCode, prefix, suffix);
} }
// Update Run button text based on completion status // Update Run button text based on completion status
@@ -869,7 +872,7 @@ function loadRandomTemplate() {
} }
function runCode() { function runCode() {
const userCode = codeEditor ? codeEditor.getValue() : ""; const userCode = codeEditor ? codeEditor.getEditableValue() : "";
const engineState = lessonEngine.getCurrentState(); const engineState = lessonEngine.getCurrentState();
const isPlayground = engineState.lesson?.mode === "playground"; const isPlayground = engineState.lesson?.mode === "playground";