<commit_before>var mil_edit = (function() {
  var root = "#editor";
  var selector = root + " #area #list";
  var raw = false; // Raw mode enabled
  var kb = false;
  var animating = false;
  var content  = "";

  /* ===================
  * Helper Functions
  * ===================== */
  function remove_at(str, pos) {
    return str.slice(0, pos) + str.slice(pos +1);
  }
  function insert_at(str, pos, cha) {
    return str.slice(0, pos) + cha + str.slice(pos)
  }

  function are_brothers(a, b) {
    if (_.contains(a.parent().children(), $(b)[0])) { return true; }
    return false;
  }
  function is_editable(c) {
    var firstChild = c.children().first();
    if (firstChild.is("strong") || firstChild.is("em") || firstChild.is("a")) {
      return true;
    } else {
      return false;
    }
  }

  function keybindings() {
    if (animating) { return false; }
    if (kb) {
      animating = true;
      $("#keys").animate({ 'width': 'auto' }, { duration: 150 }).removeClass("enabled"); 
      $(root + " #keybindings").animate({ opacity: 0 }, {
        complete : function() { 
          $(root + " #keybindings").removeClass("visible"); 
          animating = false;
        }
      });
      kb = false;
    } else {
      animating = true;
      $("#keys").animate({ 'width': '215px' }, { duration: 150 }).addClass('enabled');
      $(root + " #keybindings").addClass("visible").animate(
        { opacity: 1.0 }, { 
        duration: 600, easing: 'ease-in',
        complete : function() { animating = false; }
      });
      kb = true;
    }
  }


  /* =====================================================
  * Load and Dump Markdown
  * note: custom funcs used to perserve tree
  * see HACKERS file
  * ======================================================= */
  function load_markdown(markdownString) {
    if (typeof markdownString != "string") { return false; }

    // Looks for spaces of 2 or 4
    var lines = markdownString.split("\n");
    var root = $("<ul>"); 
    var current = root, spaces = 0;

    _.each(lines, function(line, index) {
      if (line == "") { return; }
      var matches = line.match(new RegExp("( +)?[-*] (.+)"));
      if (!matches) { return; }
      var leading = matches[1] ? matches[1].length : 0;
      var content = matches[2];

      if ((leading - 2) == spaces || (leading - 4) == spaces) {
        // Indent goes up one level
        var n = $("<li>").append("<ul>");
        current.append(n); 
        current = n.children();
      } else if ((leading + 2) == spaces ||  (leading + 4) == spaces) {
        // Indent goes down one level
        current = current.parent().parent();

      } else if (leading == spaces) {
        // Same level
      } else { return; }

      current.append("<li>" + content + "</li>");
      spaces = leading;
    });
    if ($(root).children().size() == 0) {
      load_markdown("- **Invalid** Raw Markdown List\n  * mil edit only supports a single _well-formatted_ Markdown list");
      return;
    }

    $(selector).html(root);
    text_attributes(true);
    focus.set($(selector + " li").last());
    insert_below();
    _(10).times(function(){focus.undent();});
    return true;
  }

  /* Dump */
  function dump_markdown(tabSize) {
    tabSize = (tabSize == null) ? 2 : tabSize;
    var root = $(selector).children().first();

    var ret = "";
    _.each($(selector + " li"), function (l) {
      if ($(l).attr("id") == "active") {
        $(l).html(markdown.toHTML($("#active textarea").val()));
      }
      var level = $(l).parents("ul").size() -1;
      if ($(l).children("ul").size() == 0) {
        var pre = "";
        _.times(level * tabSize, function () { pre = pre + " "; });
        pre += (level % 2 === 0) ?  "- " : "* ";
        var text = $(l).html();
        ret += pre + toMarkdown(text) + "\n";
      }
    });
    return ret;
  };

  /* ==========================
  * Focus Object (tracks focused line)
  * =========================== */
  var focus = new Object();
  focus.position_cursor =  function(position) {
    var field = $("#active textarea")[0];
    if (field.createTextRange) {
      var range = field.createTextRange();
      range.move('character', position);
      range.select();
    } else {
      if (field.selectionStart != undefined) {
        field.setSelectionRange(position, position);
      }
      field.focus();
    }
  }

  focus.position_cursor_delta = function(delta) {
    focus.position_cursor(
      $("#active textarea")[0].selectionStart + delta
    );
  }

  focus.adjust_rows = function() {<commit_msg>mil_edit.dump_markdown() no longer breaks editing also can properly do dump_markdown 2+ times successivly<commit_after>var mil_edit = (function() {
  var root = "#editor";
  var selector = root + " #area #list";
  var raw = false; // Raw mode enabled
  var kb = false;
  var animating = false;
  var content  = "";

  /* ===================
  * Helper Functions
  * ===================== */
  function remove_at(str, pos) {
    return str.slice(0, pos) + str.slice(pos +1);
  }
  function insert_at(str, pos, cha) {
    return str.slice(0, pos) + cha + str.slice(pos)
  }

  function are_brothers(a, b) {
    if (_.contains(a.parent().children(), $(b)[0])) { return true; }
    return false;
  }
  function is_editable(c) {
    var firstChild = c.children().first();
    if (firstChild.is("strong") || firstChild.is("em") || firstChild.is("a")) {
      return true;
    } else {
      return false;
    }
  }

  function keybindings() {
    if (animating) { return false; }
    if (kb) {
      animating = true;
      $("#keys").animate({ 'width': 'auto' }, { duration: 150 }).removeClass("enabled"); 
      $(root + " #keybindings").animate({ opacity: 0 }, {
        complete : function() { 
          $(root + " #keybindings").removeClass("visible"); 
          animating = false;
        }
      });
      kb = false;
    } else {
      animating = true;
      $("#keys").animate({ 'width': '215px' }, { duration: 150 }).addClass('enabled');
      $(root + " #keybindings").addClass("visible").animate(
        { opacity: 1.0 }, { 
        duration: 600, easing: 'ease-in',
        complete : function() { animating = false; }
      });
      kb = true;
    }
  }


  /* =====================================================
  * Load and Dump Markdown
  * note: custom funcs used to perserve tree
  * see HACKERS file
  * ======================================================= */
  function load_markdown(markdownString) {
    if (typeof markdownString != "string") { return false; }

    // Looks for spaces of 2 or 4
    var lines = markdownString.split("\n");
    var root = $("<ul>"); 
    var current = root, spaces = 0;

    _.each(lines, function(line, index) {
      if (line == "") { return; }
      var matches = line.match(new RegExp("( +)?[-*] (.+)"));
      if (!matches) { return; }
      var leading = matches[1] ? matches[1].length : 0;
      var content = matches[2];

      if ((leading - 2) == spaces || (leading - 4) == spaces) {
        // Indent goes up one level
        var n = $("<li>").append("<ul>");
        current.append(n); 
        current = n.children();
      } else if ((leading + 2) == spaces ||  (leading + 4) == spaces) {
        // Indent goes down one level
        current = current.parent().parent();

      } else if (leading == spaces) {
        // Same level
      } else { return; }

      current.append("<li>" + content + "</li>");
      spaces = leading;
    });
    if ($(root).children().size() == 0) {
      load_markdown("- **Invalid** Raw Markdown List\n  * mil edit only supports a single _well-formatted_ Markdown list");
      return;
    }

    $(selector).html(root);
    text_attributes(true);
    focus.set($(selector + " li").last());
    insert_below();
    _(10).times(function(){focus.undent();});
    return true;
  }

  /* Dump */
  function dump_markdown(tabSize) {
    tabSize = (tabSize == null) ? 2 : tabSize;
    var root = $(selector).children().first();

    var ret = "";
    _.each($(selector + " li"), function (l) {
      text = "";

      if ($(l).attr("id") == "active") {
        text = markdown.toHTML($("#active textarea").val());
      } else {
        var level = $(l).parents("ul").size() -1;
        if ($(l).children("ul").size() == 0) {
          var pre = "";
          _.times(level * tabSize, function () { pre = pre + " "; });
          pre += (level % 2 === 0) ?  "- " : "* ";
          text = $(l).html();
        } else {
          text = false;
        }
      }
      if (text) { ret += pre + toMarkdown(text) + "\n"; }
    });
    return ret;
  };

  /* ==========================
  * Focus Object (tracks focused line)
  * =========================== */
  var focus = new Object();
  focus.position_cursor =  function(position) {
    var field = $("#active textarea")[0];
    if (field.createTextRange) {
      var range = field.createTextRange();
      range.move('character', position);
      range.select();
    } else {
      if (field.selectionStart != undefined) {
        field.setSelectionRange(position, position);
      }
      field.focus();
    }
  }

  focus.position_cursor_delta = function(delta) {
    focus.position_cursor(
      $("#active textarea")[0].selectionStart + delta
    );
  }

  focus.adjust_rows = function() {
{'fraction_non_alphanumeric': 0.21932086825703848, 'fraction_numerical': 0.008704061895551257, 'mean_word_length': 2.487073810415886, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '1301142', 'n_tokens_mistral': 2962, 'n_tokens_neox': 2810, 'n_words': 697}