<commit_before>/*global jQuery,cyberDojo*/

var cyberDojo = (function(cd, $) {
  "use strict";

  cd.syntaxHighlightEnabled = false;
  cd.syntaxHighlightTabSize = 4;

  var fileExtension = function(filename) {
    var lastPoint = filename.lastIndexOf('.');
    if(lastPoint == -1) {
      return '';
    }
    return filename.substring(lastPoint);
  };

  var codeMirrorMode = function(filename) {
    switch(filename) {
      case 'makefile':
        return 'text/x-makefile';
      case 'instructions':
        return '';
    }

    switch(fileExtension(filename)) {
      case '.cpp':
      case '.hpp':
      case '.c':
      case '.h':
        return 'text/x-c++src';
      case '.clj':
        return 'text/x-clojure';
      case '.coffee':
        return 'text/x-coffeescript';
      case '.d':
        return 'text/x-d';
      case '.feature':
        return 'text/x-feature';
      case '.js':
        return 'text/javascript';
      case '.php':
        return 'text/x-php';
      case '.py':
        return 'text/x-python';
      case '.rb':
        return 'text/x-ruby';
      case '.sh':
        return 'text/x-sh';
      case '.vb':
        return 'text/x-vb';
      case '.vhdl':
        return 'text/x-vhdl';
    }
    return '';
  };

  var syntaxHighlightFileContentForId = function(filename) {
      return 'syntax_highlight_file_content_for_' + filename;
  };

  var switchEditorToCodeMirror = function(filename) {
    var editor = CodeMirror.fromTextArea(document.getElementById('file_content_for_' + filename),  {
        lineNumbers: true,
        matchBrackets: true,
        mode: codeMirrorMode(filename),
        autoRefresh: true,
        indentUnit: cd.syntaxHighlightTabSize,
        tabSize: cd.syntaxHighlightTabSize,
        theme: "default cyber-dojo"
    });

    editor.getWrapperElement().id = syntaxHighlightFileContentForId(filename);

    editor.setOption("extraKeys", {
        'Alt-T': function(cm) {
            $('#test-button').click();
        },
        'Alt-J': function(cm) {
            cd.loadNextFile();
        },
        'Alt-K': function(cm) {
            cd.loadPreviousFile();
        },
        'Alt-O': function(cm) {
            cd.toggleOutputFile();
        }
    });
    var lineNumbers = document.getElementById(filename + '_line_numbers');
    lineNumbers.style.display = 'none';
  };

  cd.focusSyntaxHighlightEditor = function(filename) {
      var element = document.getElementById(syntaxHighlightFileContentForId(filename));
      if(element != null) {
          element.CodeMirror.focus();
      }
  };

  cd.switchEditorIfSyntaxHighlightEnabled = function(filename) {
      if(cd.syntaxHighlightEnabled) {
          switchEditorToCodeMirror(filename);
      }
  };

  var turnSyntaxHighlightOn = function() {
      $.each($('.file_content'), function(i, editor_text_area) {
          var filename = editor_text_area.attributes['data-filename'].value;
          if(filename != 'output') {
              switchEditorToCodeMirror(filename);
          }
      });

      cd.syntaxHighlightEnabled = true;
  };

  var turnSyntaxHighlightOff = function() {
      $.each($('.CodeMirror'), function(i, editor_div) {
          editor_div.CodeMirror.toTextArea();
      });
      $.each($('.line_numbers'), function(i, line_numbers_div) {
          line_numbers_div.style.display = '';
      });

      cd.syntaxHighlightEnabled = false;
  };

  cd.toggleSyntaxHighlight = function() {
      if(cd.syntaxHighlightEnabled) {
          turnSyntaxHighlightOff();
      }
      else {
          turnSyntaxHighlightOn();
      }
  };

  cd.saveCodeFromSyntaxHighlightEditors = function() {
      $.each($('.CodeMirror'), function(i, editor_div) {
          editor_div.CodeMirror.save();
      });
  };<commit_msg>Refactored indenting in cyber-dojo_codemirror.js<commit_after>/*global jQuery,cyberDojo*/

var cyberDojo = (function(cd, $) {
  "use strict";

  cd.syntaxHighlightEnabled = false;
  cd.syntaxHighlightTabSize = 4;

  var fileExtension = function (filename) {
    var lastPoint = filename.lastIndexOf('.');
    if (lastPoint == -1) {
      return '';
    }
    return filename.substring(lastPoint);
  };

  var codeMirrorMode = function (filename) {
    switch (filename) {
      case 'makefile':
        return 'text/x-makefile';
      case 'instructions':
        return '';
    }

    switch (fileExtension(filename)) {
      case '.cpp':
      case '.hpp':
      case '.c':
      case '.h':
        return 'text/x-c++src';
      case '.clj':
        return 'text/x-clojure';
      case '.coffee':
        return 'text/x-coffeescript';
      case '.d':
        return 'text/x-d';
      case '.feature':
        return 'text/x-feature';
      case '.js':
        return 'text/javascript';
      case '.php':
        return 'text/x-php';
      case '.py':
        return 'text/x-python';
      case '.rb':
        return 'text/x-ruby';
      case '.sh':
        return 'text/x-sh';
      case '.vb':
        return 'text/x-vb';
      case '.vhdl':
        return 'text/x-vhdl';
    }
    return '';
  };

  var syntaxHighlightFileContentForId = function (filename) {
    return 'syntax_highlight_file_content_for_' + filename;
  };

  var switchEditorToCodeMirror = function (filename) {
    var editor = CodeMirror.fromTextArea(document.getElementById('file_content_for_' + filename), {
      lineNumbers: true,
      matchBrackets: true,
      mode: codeMirrorMode(filename),
      autoRefresh: true,
      indentUnit: cd.syntaxHighlightTabSize,
      tabSize: cd.syntaxHighlightTabSize,
      theme: "default cyber-dojo"
    });

    editor.getWrapperElement().id = syntaxHighlightFileContentForId(filename);

    editor.setOption("extraKeys", {
      'Alt-T': function (cm) {
        $('#test-button').click();
      },
      'Alt-J': function (cm) {
        cd.loadNextFile();
      },
      'Alt-K': function (cm) {
        cd.loadPreviousFile();
      },
      'Alt-O': function (cm) {
        cd.toggleOutputFile();
      }
    });
    var lineNumbers = document.getElementById(filename + '_line_numbers');
    lineNumbers.style.display = 'none';
  };

  cd.focusSyntaxHighlightEditor = function (filename) {
    var element = document.getElementById(syntaxHighlightFileContentForId(filename));
    if (element != null) {
      element.CodeMirror.focus();
    }
  };

  cd.switchEditorIfSyntaxHighlightEnabled = function (filename) {
    if (cd.syntaxHighlightEnabled) {
      switchEditorToCodeMirror(filename);
    }
  };

  var turnSyntaxHighlightOn = function () {
    $.each($('.file_content'), function (i, editor_text_area) {
      var filename = editor_text_area.attributes['data-filename'].value;
      if (filename != 'output') {
        switchEditorToCodeMirror(filename);
      }
    });

    cd.syntaxHighlightEnabled = true;
  };

  var turnSyntaxHighlightOff = function () {
    $.each($('.CodeMirror'), function (i, editor_div) {
      editor_div.CodeMirror.toTextArea();
    });
    $.each($('.line_numbers'), function (i, line_numbers_div) {
      line_numbers_div.style.display = '';
    });

    cd.syntaxHighlightEnabled = false;
  };

  cd.toggleSyntaxHighlight = function () {
    if (cd.syntaxHighlightEnabled) {
      turnSyntaxHighlightOff();
    }
    else {
      turnSyntaxHighlightOn();
    }
  };

  cd.saveCodeFromSyntaxHighlightEditors = function () {
    $.each($('.CodeMirror'), function (i, editor_div) {
      editor_div.CodeMirror.save();
    });
  };
{'fraction_non_alphanumeric': 0.14333556597454788, 'fraction_numerical': 0.0005358338914936369, 'mean_word_length': 2.4757914338919926, 'pattern_counts': {'":': 0, '<': 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': '5099572', 'n_tokens_mistral': 2342, 'n_tokens_neox': 2205, 'n_words': 402}