<commit_before>var Scroll = {
  positions: {},
  history: [],
  historyIndex: 0,
};

const NON_SCROLLABLE     = 0,
      SCROLLABLE_Y_DOWN  = 1,
      SCROLLABLE_Y_UP    = 2,
      SCROLLABLE_X_RIGHT = 4,
      SCROLLABLE_X_LEFT  = 8,
      SCROLLABLE = SCROLLABLE_X_LEFT | SCROLLABLE_X_RIGHT |
                   SCROLLABLE_Y_UP | SCROLLABLE_Y_DOWN;
// const SCROLLABLE_Y = SCROLLABLE_Y_UP   | SCROLLABLE_Y_DOWN,
//       SCROLLABLE_X = SCROLLABLE_X_LEFT | SCROLLABLE_X_RIGHT;

var scrollingElement = (function() {
  function getScrollType(elem) {
    var cs = getComputedStyle(elem);
    var st = NON_SCROLLABLE;
    if (cs.overflow === 'hidden')
      return st;
    if (cs.overflowX !== 'hidden' &&
        elem.offsetHeight > elem.clientHeight &&
        elem.scrollWidth > elem.clientWidth) {
      if (elem.scrollLeft > 0)
        st |= SCROLLABLE_X_LEFT;
      if (elem.scrollLeft + elem.clientWidth < elem.scrollWidth)
        st |= SCROLLABLE_X_RIGHT;
    }
    if (cs.overflowY !== 'hidden' &&
        elem.offsetWidth > elem.clientWidth &&
        elem.scrollHeight > elem.clientHeight) {
      if (elem.scrollTop > 0)
        st |= SCROLLABLE_Y_UP;
      if (elem.scrollTop + elem.clientHeight < elem.scrollHeight)
        st |= SCROLLABLE_Y_DOWN;
    }
    return st;
  }

  var lastActiveElem = null,
      lastScrollElem = null,
      clickFocus = false;

  window.resetScrollFocus = function() {
    clickFocus = false;
  };

  document.addEventListener('mousedown', function(event) {
    if (!event.isTrusted)
      return true;
    clickFocus = true;
    lastActiveElem = event.srcElement;
  });

  return function scrollingElement(dir) {
    var elem;
    if (clickFocus) {
      elem = lastActiveElem;
    } else {
      elem = lastActiveElem = document.activeElement;
    }
    if (elem === null)
      return null;
    return (function climb(elem) {
      if (elem === null)
        return lastScrollElem || document.scrollingElement;
      if (elem === document.scrollingElement)
        return elem;
      var st = getScrollType(elem);
      return st & dir ? elem : climb(elem.parentElement);
    })(elem);
  };
})();<commit_msg>Use event.target rather than event.srcElement<commit_after>var Scroll = {
  positions: {},
  history: [],
  historyIndex: 0,
};

const NON_SCROLLABLE     = 0,
      SCROLLABLE_Y_DOWN  = 1,
      SCROLLABLE_Y_UP    = 2,
      SCROLLABLE_X_RIGHT = 4,
      SCROLLABLE_X_LEFT  = 8,
      SCROLLABLE = SCROLLABLE_X_LEFT | SCROLLABLE_X_RIGHT |
                   SCROLLABLE_Y_UP | SCROLLABLE_Y_DOWN;
// const SCROLLABLE_Y = SCROLLABLE_Y_UP   | SCROLLABLE_Y_DOWN,
//       SCROLLABLE_X = SCROLLABLE_X_LEFT | SCROLLABLE_X_RIGHT;

var scrollingElement = (function() {
  function getScrollType(elem) {
    var cs = getComputedStyle(elem);
    var st = NON_SCROLLABLE;
    if (cs.overflow === 'hidden')
      return st;
    if (cs.overflowX !== 'hidden' &&
        elem.offsetHeight > elem.clientHeight &&
        elem.scrollWidth > elem.clientWidth) {
      if (elem.scrollLeft > 0)
        st |= SCROLLABLE_X_LEFT;
      if (elem.scrollLeft + elem.clientWidth < elem.scrollWidth)
        st |= SCROLLABLE_X_RIGHT;
    }
    if (cs.overflowY !== 'hidden' &&
        elem.offsetWidth > elem.clientWidth &&
        elem.scrollHeight > elem.clientHeight) {
      if (elem.scrollTop > 0)
        st |= SCROLLABLE_Y_UP;
      if (elem.scrollTop + elem.clientHeight < elem.scrollHeight)
        st |= SCROLLABLE_Y_DOWN;
    }
    return st;
  }

  var lastActiveElem = null,
      lastScrollElem = null,
      clickFocus = false;

  window.resetScrollFocus = function() {
    clickFocus = false;
  };

  document.addEventListener('mousedown', function(event) {
    if (!event.isTrusted)
      return true;
    clickFocus = true;
    lastActiveElem = event.target;
  });

  return function scrollingElement(dir) {
    var elem;
    if (clickFocus) {
      elem = lastActiveElem;
    } else {
      elem = lastActiveElem = document.activeElement;
    }
    if (elem === null)
      return null;
    return (function climb(elem) {
      if (elem === null)
        return lastScrollElem || document.scrollingElement;
      if (elem === document.scrollingElement)
        return elem;
      var st = getScrollType(elem);
      return st & dir ? elem : climb(elem.parentElement);
    })(elem);
  };
})();
{'fraction_non_alphanumeric': 0.11203319502074689, 'fraction_numerical': 0.0036883356385431073, 'mean_word_length': 2.606816292601829, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '2454866', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1428, 'n_words': 294}