Skip to content
Open
Changes from 4 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
16 changes: 14 additions & 2 deletions public/app/exercise/exercise.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@
exercise.idle = false;
connection.sendMessage('userBack', {});
}
// Save the editor content in the local storage
$window.localStorage.setItem("editor." + exercise.id + "." + editor.getOption("mode"), editor.getValue());
startIdleLoop();
}

Expand All @@ -157,6 +159,13 @@
exercise.editor.on('change', resetIdleLoop);
resizeCodeMirror();
};


function loadEditorContent() {
var editorValue = $window.localStorage.getItem("editor." + exercise.id + "." + editor.getOption("mode"));
if (editorValue != null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's one of the common best practices to use === and !== instead of == and != to prevent type coercion during comparison.
For more details about type coercion and why we want to avoid it, you can check this link: http://blog.jeremymartin.name/2008/03/understanding-loose-typing-in.html

editor.setValue(editorValue);
}

function getExercise() {
var args = {
Expand Down Expand Up @@ -212,6 +221,8 @@
exercise.id = data.id;
exercise.name = data.id.split('.').pop();

loadEditorContent();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can be removed, since the value of the editor is overriden a few lines later by exercise.code = data.code.trim();.
The editor is kept up to date with the variable exercise.code using directive from AngularJS ng-model = exercise.code


navigation.setInlesson(true);
navigation.setCurrentPageTitle(exercise.lessonName + ' / ' + exercise.name);

Expand Down Expand Up @@ -468,8 +479,8 @@
exercise.resultType = null;
exercise.result = '';
exercise.logs = '';

exercisesList.setCurrentLessonID(exercise.lessonID);

}

function updateInstructions(instructions, api) {
Expand Down Expand Up @@ -793,6 +804,7 @@
break;
}
}
loadEditorContent();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setIDEMode() should not update the value of the editor, it is not its purpose.
It would be better to let updateUI() update it if needed.

}

function toggleAPI() {
Expand Down Expand Up @@ -848,4 +860,4 @@
}
return buffer;
}
})();
})();