<commit_before>import React from 'react'
/**
 * Handles the Select action in a DOM element
 */

export default class SelectionHandler extends React.Component {
  constructor (props) {
    super(props)
    this.handleSelect = this.handleSelect.bind(this)
    this.handleDeselect = this.handleDeselect.bind(this)
  }

  componentDidMount () {
    if (this.props.onSelect) {
      document.addEventListener('keyup', this.handleSelect)
      document.addEventListener('mouseup', this.handleSelect)
      document.addEventListener('click', this.handleSelect)
      document.addEventListener('dblclick', this.handleSelect)
      document.addEventListener('scroll', this.handleSelect)
    }

    if (this.props.onDeselect) {
      document.addEventListener('selectionchange', this.handleDeselect)
    }
  }

  componentWillUnmount () {
    if (this.props.onSelect) {
      document.removeEventListener('keyup', this.handleSelect)
      document.removeEventListener('mouseup', this.handleSelect)
      document.removeEventListener('click', this.handleSelect)
      document.removeEventListener('dblclick', this.handleSelect)
      document.removeEventListener('scroll', this.handleSelect)
    }
  }

  handleSelect () {
    const selection = document.getSelection()

    if (selection.rangeCount !== 1 || !this.node) {
      return this.props.onDeselect()
    }

    const range = selection.getRangeAt(0)

    if (range.collapsed) {
      return this.props.onDeselect()
    }

    const ancestor = range.commonAncestorContainer<commit_msg>Fix a React warning in <SelectionHandler><commit_after>import React from 'react'
/**
 * Handles the Select action in a DOM element
 */

export default class SelectionHandler extends React.Component {
  constructor (props) {
    super(props)
    this.handleSelect = this.handleSelect.bind(this)
    this.handleDeselect = this.handleDeselect.bind(this)
  }

  componentDidMount () {
    if (this.props.onSelect) {
      document.addEventListener('keyup', this.handleSelect)
      document.addEventListener('mouseup', this.handleSelect)
      document.addEventListener('click', this.handleSelect)
      document.addEventListener('dblclick', this.handleSelect)
      document.addEventListener('scroll', this.handleSelect)
    }

    if (this.props.onDeselect) {
      document.addEventListener('selectionchange', this.handleDeselect)
    }
  }

  componentWillUnmount () {
    if (this.props.onSelect) {
      document.removeEventListener('keyup', this.handleSelect)
      document.removeEventListener('mouseup', this.handleSelect)
      document.removeEventListener('click', this.handleSelect)
      document.removeEventListener('dblclick', this.handleSelect)
      document.removeEventListener('scroll', this.handleSelect)
    }

    if (this.props.onDeselect) {
      document.removeEventListener('selectionchange', this.handleDeselect)
    }
  }

  handleSelect () {
    const selection = document.getSelection()

    if (selection.rangeCount !== 1 || !this.node) {
      return this.props.onDeselect()
    }

    const range = selection.getRangeAt(0)

    if (range.collapsed) {
      return this.props.onDeselect()
    }

    const ancestor = range.commonAncestorContainer
{'fraction_non_alphanumeric': 0.11201248049921997, 'fraction_numerical': 0.0012480499219968799, 'mean_word_length': 3.792227204783259, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '3955645', 'n_tokens_mistral': 887, 'n_tokens_neox': 879, 'n_words': 158}