<commit_before>(function(){
  "use strict";

  const d = document;

  function createDiv(className) {
    const div = d.createElement('div');
    div.className = className;
    return div;
  }

  function appendDiv(node, className) {
    return node.appendChild(createDiv(className));
  }

  function createNode(text) {
    const node = createDiv('Node collapsed');
    appendDiv(node, 'Expander');
    const content = appendDiv(node, 'Content');
    content.contentEditable = 'true';
    if(text) content.textContent = text;
    appendDiv(node, 'Children');
    return node;
  }

  function expanderElement(node) { return node.firstChild; }
  function contentElement(node) { return node.children[1]; }
  function childrenElement(node) { return node.lastChild; }
  function parentNode(node) { 
    node = node.parentElement;
    if(node && node.classList.contains('Children')) return node.parentElement;
    return null;
  }

  function isExpanded(node) { return node.classList.contains('expanded'); }
  function swapClass(node, oldClass, newClass) {
    node.classList.remove(oldClass);
    node.classList.add(newClass);
  }
  function expand(node) { swapClass(node, 'collapsed', 'expanded'); }
  function collapse(node) { swapClass(node, 'expanded', 'collapsed'); }
  function toggle(node) { (isExpanded(node)?collapse:expand)(node); }

  function focusContent(node) {
    if(node) contentElement(node).focus();
  }

  function lastVisibleLeaf(node) {
    while(node && isExpanded(node)) {
      var lastChild = childrenElement(node).lastChild;
      if(lastChild) node = lastChild;
    }
    return node;
  }

  function focusPrevContent(node) {
    focusContent(lastVisibleLeaf(node.previousSibling) || parentNode(node));
  }

  function focusNextContent(node) {
    var next = isExpanded(node) ? childrenElement(node).firstChild : node.nextSibling;
    if(!next) {
      const parent = parentNode(node);
      if(parent) next = parent.nextSibling;
    }
    focusContent(next);
  }

  function appendSibling(node, sibling) {
    return node.insertAdjacentElement('afterEnd', sibling);
  }

  function prependSibling(node, sibling) {
    return node.insertAdjacentElement('beforeBegin', sibling);
  }

  function appendChild(node, child) {
    return childrenElement(node).appendChild(child);
  }

  function appendNewSiblingOrFirstChild(node) {
    if(isExpanded(node)) {
      const firstChild = childrenElement(node).firstChild;
      if(firstChild) {
        focusContent(prependSibling(firstChild, createNode()));
        return;
      }
    }
    focusContent(appendSibling(node, createNode()));
  }

  function indent(node) {
    const prev = node.previousSibling;
    if(prev) {
      expand(prev);
      appendChild(prev, node);
      focusContent(node);
    }
  }

  function outdent(node) {
    const parent = parentNode(node);
    if(parent) {
      appendSibling(parent, node);
      focusContent(node);
    }
  }

  function moveUp(node) {
    const prev = node.previousSibling || parentNode(node);
    if(prev) {
      prependSibling(prev, node);
      focusContent(node);
    }
  }

  function moveDown(node) {
    const next = node.nextSibling || parentNode(node);
    if(next) {
      appendSibling(next, node);<commit_msg>Moving a child outside a parent should collapse the parent if it's now empty<commit_after>(function(){
  "use strict";

  const d = document;

  function createDiv(className) {
    const div = d.createElement('div');
    div.className = className;
    return div;
  }

  function appendDiv(node, className) {
    return node.appendChild(createDiv(className));
  }

  function createNode(text) {
    const node = createDiv('Node collapsed');
    appendDiv(node, 'Expander');
    const content = appendDiv(node, 'Content');
    content.contentEditable = 'true';
    if(text) content.textContent = text;
    appendDiv(node, 'Children');
    return node;
  }

  function expanderElement(node) { return node.firstChild; }
  function contentElement(node) { return node.children[1]; }
  function childrenElement(node) { return node.lastChild; }
  function parentNode(node) { 
    node = node.parentElement;
    if(node && node.classList.contains('Children')) return node.parentElement;
    return null;
  }

  function isExpanded(node) { return node.classList.contains('expanded'); }
  function swapClass(node, oldClass, newClass) {
    node.classList.remove(oldClass);
    node.classList.add(newClass);
  }
  function expand(node) { swapClass(node, 'collapsed', 'expanded'); }
  function collapse(node) { swapClass(node, 'expanded', 'collapsed'); }
  function toggle(node) { (isExpanded(node)?collapse:expand)(node); }
  function collapseIfEmpty(node) { if(!childrenElement(node).firstChild) collapse(node); }

  function focusContent(node) {
    if(node) contentElement(node).focus();
  }

  function lastVisibleLeaf(node) {
    while(node && isExpanded(node)) {
      var lastChild = childrenElement(node).lastChild;
      if(lastChild) node = lastChild;
      else break;
    }
    return node;
  }

  function focusPrevContent(node) {
    focusContent(lastVisibleLeaf(node.previousSibling) || parentNode(node));
  }

  function focusNextContent(node) {
    var next = isExpanded(node) ? childrenElement(node).firstChild : node.nextSibling;
    if(!next) {
      const parent = parentNode(node);
      if(parent) next = parent.nextSibling;
    }
    focusContent(next);
  }

  function appendSibling(node, sibling) {
    return node.insertAdjacentElement('afterEnd', sibling);
  }

  function prependSibling(node, sibling) {
    return node.insertAdjacentElement('beforeBegin', sibling);
  }

  function appendChild(node, child) {
    return childrenElement(node).appendChild(child);
  }

  function appendNewSiblingOrFirstChild(node) {
    if(isExpanded(node)) {
      const firstChild = childrenElement(node).firstChild;
      if(firstChild) {
        focusContent(prependSibling(firstChild, createNode()));
        return;
      }
    }
    focusContent(appendSibling(node, createNode()));
  }

  function indent(node) {
    const prev = node.previousSibling;
    if(prev) {
      expand(prev);
      appendChild(prev, node);
      focusContent(node);
    }
  }

  function outdent(node) {
    const parent = parentNode(node);
    if(parent) {
      appendSibling(parent, node);
      collapseIfEmpty(parent);
      focusContent(node);
    }
  }

  function moveUp(node) {
    const parent = parentNode(node);
    const prev = node.previousSibling || parent;
    if(prev) {
      prependSibling(prev, node);
      collapseIfEmpty(parent);
      focusContent(node);
    }
  }

  function moveDown(node) {
    const parent = parentNode(node);
    const next = node.nextSibling || parent;
    if(next) {
      appendSibling(next, node);
      collapseIfEmpty(parent);
{'fraction_non_alphanumeric': 0.1254222352768395, 'fraction_numerical': 0.000293728888236158, 'mean_word_length': 3.755586592178771, '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': '1960651', 'n_tokens_mistral': 2083, 'n_tokens_neox': 2066, 'n_words': 403}