<commit_before>import { PureComponent } from 'react';
import PropTypes from 'prop-types';

class ScrollToHighlightIndex extends PureComponent {
  // eslint-disable-line react/prefer-stateless-function
  componentDidMount() {
    setTimeout(this.handleScroll, 150);
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.content.html !== this.props.content.html) {
      setTimeout(this.handleScroll, 150);
    }
  }

  handleScroll = () => {
    const { idx, targetElementsSelector } = this.props;
    const e = idx
      ? document.querySelectorAll(targetElementsSelector)[idx]
      : document.querySelectorAll(targetElementsSelector)[0];
    if (e) {
      window.scrollTo({
        behavior: 'smooth',
        left: 0,
        top: e.offsetTop - 200<commit_msg>Calculate top position even on not table first level elements<commit_after>import { PureComponent } from 'react';
import PropTypes from 'prop-types';

class ScrollToHighlightIndex extends PureComponent {
  // eslint-disable-line react/prefer-stateless-function
  componentDidMount() {
    setTimeout(this.handleScroll, 150);
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.content.html !== this.props.content.html) {
      setTimeout(this.handleScroll, 150);
    }
  }

  handleScroll = () => {
    const { idx, targetElementsSelector } = this.props;
    const e = idx
      ? document.querySelectorAll(targetElementsSelector)[idx]
      : document.querySelectorAll(targetElementsSelector)[0];

    const topPosition = element => {
      const PADDING = -200;
      let firstLevelElement = element;
      let elementPosition = firstLevelElement.offsetTop;
      while (firstLevelElement.tagName !== 'TABLE') {
        elementPosition += firstLevelElement.offsetParent.offsetTop;
        firstLevelElement = firstLevelElement.offsetParent;
      }
      return elementPosition + PADDING;
    };

    if (e) {
      window.scrollTo({
        behavior: 'smooth',
        left: 0,
        top: topPosition(e)
{'fraction_non_alphanumeric': 0.10832497492477432, 'fraction_numerical': 0.011033099297893681, 'mean_word_length': 3.3846153846153846, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '5221078', 'n_tokens_mistral': 583, 'n_tokens_neox': 554, 'n_words': 115}