Insert text written after last autosave in pp session

This commit is contained in:
kiragrammel
2023-09-11 22:44:48 +02:00
committed by Sebastian Serth
parent 6e0dc9d7bc
commit 914adeed42
6 changed files with 37 additions and 12 deletions

View File

@ -311,7 +311,7 @@ var CodeOceanEditor = {
editor.commands.bindKey("ctrl+alt+0", null);
this.editors.push(editor);
this.editor_for_file.set($(element).parent().data('filename'), editor);
this.editor_for_file.set($(element).data('file-id'), editor);
var session = editor.getSession();
var mode = $(element).data('mode')
session.setMode(mode);
@ -753,7 +753,7 @@ var CodeOceanEditor = {
this.setActiveFile(frame.data('filename'), file_id);
this.selectFileInJsTree($('#files'), file_id);
const editor = this.editor_for_file.get(file);
const editor = this.editor_for_file.get(file_id);
editor.gotoLine(line, 0);
event.preventDefault();
},
@ -1061,7 +1061,7 @@ var CodeOceanEditor = {
},
applyChanges: function (delta, active_file) {
const editor = this.editor_for_file.get(active_file.filename)
const editor = this.editor_for_file.get(active_file.id)
editor.session.doc.applyDeltas([delta]);
},

View File

@ -119,15 +119,21 @@ CodeOceanEditorSubmissions = {
url: $('#start-over').data('url') || $('#start-over-active-file').data('url')
}).done(function(response) {
this.hideSpinner();
_.each(this.editors, function(editor) {
var file_id = $(editor.container).data('file-id');
var file = _.find(response.files, function(file) {
return file.id === file_id;
});
if(file && !onlyActiveFile || file && file.id === CodeOceanEditor.active_file.id){
editor.setValue(file.content);
}
}.bind(this));
this.setEditorContent(response, onlyActiveFile);
}.bind(this));
},
setEditorContent: function(new_content, onlyActiveFile = false) {
_.each(this.editors, function(editor) {
const editor_file_id = $(editor.container).data('file-id');
const found_file = _.find(new_content.files, function(file) {
// File.id is used to reload the exercise and file.file_id is used to update the editor content for pair programming group members
return (file.id || file.file_id) === editor_file_id;
});
if(found_file && !onlyActiveFile || found_file && found_file.id === CodeOceanEditor.active_file.id){
editor.setValue(found_file.content);
editor.clearSelection();
}
}.bind(this));
},