Skip to content

Commit 809c53d

Browse files
committed
ACE Editor: Cache string with LF endings only
Caching the content of the ACE editor with CRLF might cause unintended side effects when restoring the content (since we split by LF in some cases). For now, we adjust the caching strategy accordingly.
1 parent 651dae6 commit 809c53d

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

app/assets/javascripts/editor/editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ var CodeOceanEditor = {
11521152
// Persist the content of the editors in a hidden textarea to enable Turbo caching.
11531153
// In this case, we iterate over _all_ editors, not just writable ones.
11541154
for (const [file_id, editor] of this.editor_for_file) {
1155-
const file_content = editor.getValue();
1155+
const file_content = editor.getValue().replace(/\r\n/g, '\n');
11561156
const editorContent = $(`.editor-content[data-file-id='${file_id}']`);
11571157
editorContent.text(file_content);
11581158
}

app/assets/javascripts/exercises.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ $(document).on('turbo-migration:load', function () {
3737

3838
function unloadTeacherEditor() {
3939
$(document).off('theme:change:ace');
40-
const value = editor.getValue();
40+
const value = editor.getValue().replace(/\r\n/g, '\n');
4141
editor.destroy();
4242
// "Restore" the editor's content to the original element for caching.
4343
textarea.val = value;

app/assets/javascripts/request_for_comments.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ $(document).on('turbo-migration:load', function () {
399399
$(document).off('theme:change:ace');
400400
$('.editor').each(function (_, editor) {
401401
const aceEditor = ace.edit(editor);
402-
const value = aceEditor.getValue();
402+
const value = aceEditor.getValue().replace(/\r\n/g, '\n');
403403
aceEditor.destroy();
404404
// "Restore" the editor's content to the original element for caching.
405405
editor.textContent = value;

0 commit comments

Comments
 (0)