<commit_before>var dynamicEditors = [];

function setupAceEditors() {
  $(".editor").each(function (index, textarea) {
    var editor = setupAceEditor(textarea);
    var language = $(textarea).data('editor-language');
    if (language === 'dynamic') {
      dynamicEditors.push(editor);
    } else {
      setEditorLanguage(editor, language);
    }
  });
}

function setupAceEditor(textarea) {
  var form = textarea.form;

  var editor = ace.edit(textarea);
  editor.container.id = "editor-container";
  editor.setOptions({
    minLines: 15,
    maxLines: Infinity,
    wrap: true
  });
  editor.setFontSize(13);

  form.addEventListener("submit", function () {
    textarea.style.visibility = "hidden";
    textarea.value = editor.getValue();
    form.appendChild(textarea)
  });

  return editor;
}

function onSelectUpdateAceEditor() {
  $("#exercise_language_id").change(updateAceEditorLanguage);
}

function updateAceEditorLanguage() {
  var language = $("#exercise_language_id").find(":selected").html() || $('#exercise_language').val();
  if (language !== undefined) {
    dynamicEditors.forEach(function (e) {
      setEditorLanguage(e, language);
    })
  }
}

function setEditorLanguage(editor, language) {
  editor.getSession().setMode("ace/mode/" + language.toLowerCase())
}

$(document).on('ready page:load', function () {
  setupAceEditors();
  updateAceEditorLanguage();
  onSelectUpdateAceEditor();
});

<commit_msg>Autofocus first editor<commit_after>var dynamicEditors = [];

function setupAceEditors() {
  var editors = $(".editor").map(function (index, textarea) {
    var editor = setupAceEditor(textarea);
    var language = $(textarea).data('editor-language');
    if (language === 'dynamic') {
      dynamicEditors.push(editor);
    } else {
      setEditorLanguage(editor, language);
    }
    return editor;
  });

  if (editors[0]) {
    editors[0].focus();
  }
}

function setupAceEditor(textarea) {
  var form = textarea.form;

  var editor = ace.edit(textarea);
  editor.container.id = "editor-container";
  editor.setOptions({
    minLines: 15,
    maxLines: Infinity,
    wrap: true
  });
  editor.setFontSize(13);

  form.addEventListener("submit", function () {
    textarea.style.visibility = "hidden";
    textarea.value = editor.getValue();
    form.appendChild(textarea)
  });

  return editor;
}

function onSelectUpdateAceEditor() {
  $("#exercise_language_id").change(updateAceEditorLanguage);
}

function updateAceEditorLanguage() {
  var language = $("#exercise_language_id").find(":selected").html() || $('#exercise_language').val();
  if (language !== undefined) {
    dynamicEditors.forEach(function (e) {
      setEditorLanguage(e, language);
    })
  }
}

function setEditorLanguage(editor, language) {
  editor.getSession().setMode("ace/mode/" + language.toLowerCase())
}

$(document).on('ready page:load', function () {
  setupAceEditors();
  updateAceEditorLanguage();
  onSelectUpdateAceEditor();
});


{'fraction_non_alphanumeric': 0.15910629654705485, 'fraction_numerical': 0.003385240352064997, 'mean_word_length': 4.362976406533575, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6953061', 'n_tokens_mistral': 927, 'n_tokens_neox': 895, 'n_words': 157}