<commit_before>var Find = {
  highlights: [],
  matches: [],
  index: 0,
  tries: 0
};

Find.setIndex = function() {
  for (var i = 0; i < this.matches.length; i++) {
    var br = this.matches[i].getBoundingClientRect();
    if (br.top > 0 && br.left > 0) {
      this.index = i - 1;
      HUD.display(this.index + 1 + ' / ' + this.matches.length);
      break;
    }
  }
};

Find.getSelectedTextNode = function() {
  return (this.matches.length &&
          this.matches[this.index] &&
          this.matches[this.index].firstChild)
    || false;
};

Find.focusParentLink = function(node) {
  do {
    if (node.hasAttribute('href')) {
      node.focus();
      return true;
    }
  } while (node = node.parentElement);
  return false;
};

Find.getCurrentMatch = function() {
  return this.matches[this.index] || null;
};

Find.search = function(reverse, repeats, ignoreFocus) {
  var activeHighlight = settings.activehighlight;
  if (Find.swap) {
    reverse = !reverse;
  }
  if (!this.matches.length) {
    return HUD.display('No matches', 1);
  }
  if (this.index >= 0) {
    this.matches[this.index].style.backgroundColor = '';
  }
  if (reverse && repeats === 1 && this.index === 0) {
    this.index = this.matches.length - 1;
  } else if (!reverse && repeats === 1 &&
             this.index + 1 === this.matches.length) {
    this.index = 0;
  } else {
    this.index = (this.index + (reverse ? -1 : 1) * repeats)
      .mod(this.matches.length);
  }
  if (!DOM.isVisible(this.matches[this.index])) {
    this.matches.splice(this.index, 1);
    this.tries++;
    if (this.tries > this.matches.length) {
      return;
    }
    if (this.swap) {
      return this.search(!reverse, 1);
    }
    return this.search(reverse, 1);
  } else {
    this.tries = 0;
  }
  var br = this.matches[this.index].getBoundingClientRect();
  var origTop = document.body.scrollTop;
  if (!ignoreFocus) {
    document.activeElement.blur();
    document.body.focus();
  }
  var isLink = ignoreFocus ? false : this.focusParentLink(this.matches[this.index]);
  this.matches[this.index].style.backgroundColor = activeHighlight;<commit_msg>Fix for buggy search highlight<commit_after>var Find = {
  highlights: [],
  matches: [],
  index: 0,
  tries: 0
};

Find.setIndex = function() {
  for (var i = 0; i < this.matches.length; i++) {
    var br = this.matches[i].getBoundingClientRect();
    if (br.top > 0 && br.left > 0) {
      this.index = i - 1;
      HUD.display(this.index + 1 + ' / ' + this.matches.length);
      break;
    }
  }
};

Find.getSelectedTextNode = function() {
  return (this.matches.length &&
          this.matches[this.index] &&
          this.matches[this.index].firstChild)
    || false;
};

Find.focusParentLink = function(node) {
  do {
    if (node.hasAttribute('href')) {
      node.focus();
      return true;
    }
  } while (node = node.parentElement);
  return false;
};

Find.getCurrentMatch = function() {
  return this.matches[this.index] || null;
};

Find.search = function(reverse, repeats, ignoreFocus) {
  var activeHighlight = settings.activehighlight;
  if (Find.swap) {
    reverse = !reverse;
  }
  if (!this.matches.length) {
    return HUD.display('No matches', 1);
  }
  if (this.index >= 0) {
    this.matches[this.index].style.backgroundColor = settings.highlight;
  }
  if (reverse && repeats === 1 && this.index === 0) {
    this.index = this.matches.length - 1;
  } else if (!reverse && repeats === 1 &&
             this.index + 1 === this.matches.length) {
    this.index = 0;
  } else {
    this.index = (this.index + (reverse ? -1 : 1) * repeats)
      .mod(this.matches.length);
  }
  if (!DOM.isVisible(this.matches[this.index])) {
    this.matches.splice(this.index, 1);
    this.tries++;
    if (this.tries > this.matches.length) {
      return;
    }
    if (this.swap) {
      return this.search(!reverse, 1);
    }
    return this.search(reverse, 1);
  } else {
    this.tries = 0;
  }
  var br = this.matches[this.index].getBoundingClientRect();
  var origTop = document.body.scrollTop;
  if (!ignoreFocus) {
    document.activeElement.blur();
    document.body.focus();
  }
  var isLink = ignoreFocus ? false : this.focusParentLink(this.matches[this.index]);
  this.matches[this.index].style.backgroundColor = activeHighlight;
{'fraction_non_alphanumeric': 0.165770399812953, 'fraction_numerical': 0.009819967266775777, 'mean_word_length': 2.7992895204262878, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1168772', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1437, 'n_words': 288}