<commit_before>EnhancedPullRequest.load(function () {
  /**
   * Adds a reply icon to the given context.
   *
   * @param {Element|jQuery} context
   *   where to add the icon (something containing an element of the
   *   "timeline-comment-actions" class)
   * @returns {jQuery} the icon that was created
   */
  function addReplyIconTo(context) {
    return $('<button type="button" title="Reply" aria-label="Reply" />')
      .addClass('epr epr-reply-button btn-link timeline-comment-action')
      .append($('<img />', {src: chrome.extension.getURL('images/reply.svg')}))
      .prependTo($('.timeline-comment-actions', context));
  }

  /**
   * Quotes the given message to form a reply.
   *
   * @param {String} message - original message (in Markdown)
   * @returns {String} quoted text for replying (in Markdown)
   */
  function replyTextFor(message) {
    return '\n\n> ' + message.replace(/\n/g, '\n> ');
  }

  /**
   * Adds reply text.
   *
   * @param {Element} commentContainer - container with the original comment
   * @param {jQuery} $replyTextarea - textarea to add the reply text to
   */
  function addReplyTextTo(commentContainer, $replyTextarea) {
    const commentBody = $('.js-comment-body', commentContainer).html();
    const replyText = replyTextFor(toMarkdown(
      commentBody, {gfm: true, converters: EnhancedPullRequest.MdConverters}
    ));
    $replyTextarea.val(replyText).focus();
    $replyTextarea[0].setSelectionRange(0, 0);
  }

  const $newCommentField = $('#new_comment_field');

  // Replies for issue comments
  $('div[id|="issuecomment"]').each(function (i, commentContainer) {
    addReplyIconTo(commentContainer).click(function () {
      addReplyTextTo(commentContainer, $newCommentField);
    });
  });

  // Replies for line comments
  $('.line-comments').each(function () {
    const $commentButton = $('.js-toggle-inline-comment-form', this);
    const $commentTextarea = $('.inline-comment-form textarea', this);

    $('.commit-comment', this).each(function (i, commentContainer) {
      addReplyIconTo(commentContainer).click(function () {
        if ($commentTextarea.is(':hidden')) {
          $commentButton.click();
        }
        addReplyTextTo(commentContainer, $commentTextarea);
      });
    });
  });
});<commit_msg>Avoid function recreation in reply.js<commit_after>(function () {
  /**
   * Adds a reply icon to the given context.
   *
   * @param {Element|jQuery} context
   *   where to add the icon (something containing an element of the
   *   "timeline-comment-actions" class)
   * @returns {jQuery} the icon that was created
   */
  function addReplyIconTo(context) {
    return $('<button type="button" title="Reply" aria-label="Reply" />')
      .addClass('epr epr-reply-button btn-link timeline-comment-action')
      .append($('<img />', {src: chrome.extension.getURL('images/reply.svg')}))
      .prependTo($('.timeline-comment-actions', context));
  }

  /**
   * Quotes the given message to form a reply.
   *
   * @param {String} message - original message (in Markdown)
   * @returns {String} quoted text for replying (in Markdown)
   */
  function replyTextFor(message) {
    return '\n\n> ' + message.replace(/\n/g, '\n> ');
  }

  /**
   * Adds reply text.
   *
   * @param {Element} commentContainer - container with the original comment
   * @param {jQuery} $replyTextarea - textarea to add the reply text to
   */
  function addReplyTextTo(commentContainer, $replyTextarea) {
    const commentBody = $('.js-comment-body', commentContainer).html();
    const replyText = replyTextFor(toMarkdown(
      commentBody, {gfm: true, converters: EnhancedPullRequest.MdConverters}
    ));
    $replyTextarea.val(replyText).focus();
    $replyTextarea[0].setSelectionRange(0, 0);
  }

  EnhancedPullRequest.load(function () {
    const $newCommentField = $('#new_comment_field');

    // Replies for issue comments
    $('div[id|="issuecomment"]').each(function (i, commentContainer) {
      addReplyIconTo(commentContainer).click(function () {
        addReplyTextTo(commentContainer, $newCommentField);
      });
    });

    // Replies for line comments
    $('.line-comments').each(function () {
      const $commentButton = $('.js-toggle-inline-comment-form', this);
      const $commentTextarea = $('.inline-comment-form textarea', this);

      $('.commit-comment', this).each(function (i, commentContainer) {
        addReplyIconTo(commentContainer).click(function () {
          if ($commentTextarea.is(':hidden')) {
            $commentButton.click();
          }
          addReplyTextTo(commentContainer, $commentTextarea);
        });
      });
    });
  });
})();
{'fraction_non_alphanumeric': 0.15318601158549666, 'fraction_numerical': 0.0012872774082814847, 'mean_word_length': 3.389830508474576, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '1517280', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1388, 'n_words': 311}