<commit_before><script>
//<![CDATA[
  var selected_markable_id = null;
  var selected_extra_mark_id = null;
  var positions = null;
  var modal = null;
  var init_content_width = 0;
  var init_code_pane_width = 0;

  var annotation_manager = null;
  var syntax_highlighter_adapter = null;

  var ANNOTATION_TYPES = {
    CODE: 0,
    IMAGE: 1,
    PDF: 2
  };

  // Enum to tell the code if an image, code, or pdf is being shown
  // in the codeviewer
  var annotation_type;

  function source_code_ready() {
    annotation_type = ANNOTATION_TYPES.CODE;

    document.getElementById('select_file_id').disabled = false;

    syntax_highlighter_adapter = new SyntaxHighlighter1p5Adapter(
        jQuery('.dp-highlighter')[0].getElementsBySelector('ol')[0]);

    // Apply modifications to Syntax Highlighter
    syntax_highlighter_adapter.applyMods();

    var collection   = new SourceCodeLineArray();
    var line_factory = new SourceCodeLineFactory();
    var line_manager = new SourceCodeLineManager(syntax_highlighter_adapter, line_factory, collection);
    var annotation_text_manager   = new AnnotationTextManager();
    var annotation_text_displayer = new AnnotationTextDisplayer();

    annotation_manager = new SourceCodeLineAnnotations(line_manager, annotation_text_manager, annotation_text_displayer);
  }

  // A version of source_code_ready for image files.
  function source_code_ready_for_image() {
    annotation_type = ANNOTATION_TYPES.IMAGE;

    var image_event_handler       = new ImageEventHandler();
    var annotation_text_manager   = new AnnotationTextManager();
    var annotation_text_displayer = new AnnotationTextDisplayer();

    annotation_manager = new ImageAnnotationGrid(image_event_handler,
                                                 annotation_text_manager,
                                                 annotation_text_displayer);

    document.getElementById('select_file_id').disabled = false;
  }

  /**
   * Prepare annotation for pdf annotations.
   *
   * @param {PDFView} pdfView     PDF Viewer
   * @param {String}  pdfViewerId The ID of the PDF viewer.
   */
  function source_code_ready_for_pdf(pdfView, pdfViewerId) {
    annotation_type = ANNOTATION_TYPES.PDF;

    annotation_manager = new PdfAnnotationManager(pdfView, pdfViewerId);
    annotation_manager.resetAngle();

  }

  /**
   * Called when annotations are being added to the view.
   *
   * @param {string} annotation_text_id ID of the annotation text
   * @param {string} content            Text for the annotation
   */
  function add_annotation_text(annotation_text_id, content) {
    if (annotation_type === ANNOTATION_TYPES.PDF) {
      add_pdf_annotation(annotation_text_id, content,
        annotation_manager.selectionRectangleAsInts());
    } else {
      var annotation_text = new AnnotationText(annotation_text_id, 0, content);
      annotation_manager.registerAnnotationText(annotation_text);
    }
  }

  // Register an image_annotation with the image annotation_grid
  function add_to_annotation_grid(extracted_coords) {
    annotation_manager.add_to_grid(JSON.parse(extracted_coords));
  }

  function add_pdf_annotation(annotation_text_id, content, extracted_coords) {
    var coords = (typeof extracted_coords === 'string' ? JSON.parse(extracted_coords) : extracted_coords);
    annotation_manager.addAnnotation(annotation_text_id, content, coords);

    //since we stored the coordinates in unrotated form, when making a new annotation in a rotated orientation, we need to 
    //rotate it
    var annotations = document.getElementsByClassName("annotation_holder");
    for (var i = 0; i < angle / 90; i++)
    {
      rotate_pdf_annotation(annotations[annotations.length - 1]);
    }
  }

  function add_annotation(annotation_id, range, annotation_text_id) {
    annotation_manager.annotateRange(annotation_id, range, annotation_text_id);
  }

  function remove_annotation(annotation_id, range, annotation_text_id) {
    if (annotation_manager.getAnnotationTextManager().annotationTextExists(annotation_text_id)) {
      annotation_manager.remove_annotation(annotation_id, range, annotation_text_id);
    }
  }

  /**
   * Update the text in an annotation.
   */
  function update_annotation_text(annotation_text_id, new_content) {
    if (annotation_manager.getAnnotationTextManager().annotationTextExists(annotation_text_id)) {
      annotation_manager
        .getAnnotationTextManager()
        .getAnnotationText(annotation_text_id)<commit_msg>fixed bug preventing annotations from rendering<commit_after><script>
//<![CDATA[
  var selected_markable_id = null;
  var selected_extra_mark_id = null;
  var positions = null;
  var modal = null;
  var init_content_width = 0;
  var init_code_pane_width = 0;

  var annotation_manager = null;
  var syntax_highlighter_adapter = null;

  var ANNOTATION_TYPES = {
    CODE: 0,
    IMAGE: 1,
    PDF: 2
  };

  // Enum to tell the code if an image, code, or pdf is being shown
  // in the codeviewer
  var annotation_type;

  function source_code_ready() {
    annotation_type = ANNOTATION_TYPES.CODE;

    document.getElementById('select_file_id').disabled = false;

    syntax_highlighter_adapter = new SyntaxHighlighter1p5Adapter(
        jQuery('.dp-highlighter')[0].getElementsBySelector('ol')[0]);

    // Apply modifications to Syntax Highlighter
    syntax_highlighter_adapter.applyMods();

    var collection   = new SourceCodeLineArray();
    var line_factory = new SourceCodeLineFactory();
    var line_manager = new SourceCodeLineManager(syntax_highlighter_adapter, line_factory, collection);
    var annotation_text_manager   = new AnnotationTextManager();
    var annotation_text_displayer = new AnnotationTextDisplayer();

    annotation_manager = new SourceCodeLineAnnotations(line_manager, annotation_text_manager, annotation_text_displayer);
  }

  // A version of source_code_ready for image files.
  function source_code_ready_for_image() {
    annotation_type = ANNOTATION_TYPES.IMAGE;

    var image_event_handler       = new ImageEventHandler();
    var annotation_text_manager   = new AnnotationTextManager();
    var annotation_text_displayer = new AnnotationTextDisplayer();

    annotation_manager = new ImageAnnotationGrid(image_event_handler,
                                                 annotation_text_manager,
                                                 annotation_text_displayer);

    document.getElementById('select_file_id').disabled = false;
  }

  /**
   * Prepare annotation for pdf annotations.
   *
   * @param {PDFView} pdfView     PDF Viewer
   * @param {String}  pdfViewerId The ID of the PDF viewer.
   */
  function source_code_ready_for_pdf(pdfView, pdfViewerId) {
    annotation_type = ANNOTATION_TYPES.PDF;

    annotation_manager = new PdfAnnotationManager(pdfView, pdfViewerId);
    annotation_manager.resetAngle();

  }

  /**
   * Called when annotations are being added to the view.
   *
   * @param {string} annotation_text_id ID of the annotation text
   * @param {string} content            Text for the annotation
   */
  function add_annotation_text(annotation_text_id, content) {
    if (annotation_type === ANNOTATION_TYPES.PDF) {
      add_pdf_annotation(annotation_text_id, content,
        annotation_manager.selectionRectangleAsInts());
    } else {
      var annotation_text = new AnnotationText(annotation_text_id, 0, content);
      annotation_manager.registerAnnotationText(annotation_text);
    }
  }

  // Register an image_annotation with the image annotation_grid
  function add_to_annotation_grid(extracted_coords) {
    annotation_manager.add_to_grid(JSON.parse(extracted_coords));
  }

  function add_pdf_annotation(annotation_text_id, content, extracted_coords) {
    var coords = (typeof extracted_coords === 'string' ? JSON.parse(extracted_coords) : extracted_coords);
    annotation_manager.addAnnotation(annotation_text_id, content, coords);

    // //since we stored the coordinates in unrotated form, when making a new annotation in a rotated orientation, we need to 
    // //rotate it
    // var annotations = document.getElementsByClassName("annotation_holder");
    // for (var i = 0; i < angle / 90; i++)
    // {
    //   rotate_pdf_annotation(annotations[annotations.length - 1]);
    // }
  }

  function add_annotation(annotation_id, range, annotation_text_id) {
    annotation_manager.annotateRange(annotation_id, range, annotation_text_id);
  }

  function remove_annotation(annotation_id, range, annotation_text_id) {
    if (annotation_manager.getAnnotationTextManager().annotationTextExists(annotation_text_id)) {
      annotation_manager.remove_annotation(annotation_id, range, annotation_text_id);
    }
  }

  /**
   * Update the text in an annotation.
   */
  function update_annotation_text(annotation_text_id, new_content) {
    if (annotation_manager.getAnnotationTextManager().annotationTextExists(annotation_text_id)) {
      annotation_manager
        .getAnnotationTextManager()
        .getAnnotationText(annotation_text_id)
{'fraction_non_alphanumeric': 0.08132963988919667, 'fraction_numerical': 0.0031024930747922436, 'mean_word_length': 3.9027702335687127, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6191969', 'n_tokens_mistral': 2681, 'n_tokens_neox': 2528, 'n_words': 574}