<commit_before>// @flow
/* eslint-env browser */
import React, {Component} from 'react'
import {Box, Icon, Input, Text} from '../../common-adapters'
import {globalColors, globalMargins, globalStyles} from '../../styles'
import {Picker} from 'emoji-mart'
import {backgroundImageFn} from '../../common-adapters/emoji'

import type {Props} from './input'

type State = {
  emojiPickerOpen: boolean,
  text: string,
}

class Conversation extends Component<void, Props, State> {
  _input: any;
  _fileInput: any;
  state: State;

  _setRef = r => {
    this._input = r
  }

  constructor (props: Props) {
    super(props)
    const {emojiPickerOpen} = props
    this.state = {emojiPickerOpen, text: this.props.defaultText}
  }

  componentDidMount () {
    document.body.addEventListener('keydown', this._globalKeyDownHandler)
  }

  componentWillUnmount () {
    document.body.removeEventListener('keydown', this._globalKeyDownHandler)
  }

  componentDidUpdate (prevProps: Props) {
    if (!this.props.isLoading && prevProps.isLoading) {
      this.focusInput()
    }
  }

  _globalKeyDownHandler = (ev: Event) => {
    if (!this._input) {
      return
    }

    const target = ev.target
    if (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement) {
      return
    }

    this._input.focus()
  }

  _insertEmoji (emojiColons: string) {
    const text: string = this.state.text || ''
    if (this._input) {
      const {selectionStart = 0, selectionEnd = 0} = this._input.selections() || {}
      const nextText = [text.substring(0, selectionStart), emojiColons, text.substring(selectionEnd)].join('')
      this.setState({text: nextText})
      this.focusInput()<commit_msg>allow copy command to not change input (#5687)<commit_after>// @flow
/* eslint-env browser */
import React, {Component} from 'react'
import {Box, Icon, Input, Text} from '../../common-adapters'
import {globalColors, globalMargins, globalStyles} from '../../styles'
import {Picker} from 'emoji-mart'
import {backgroundImageFn} from '../../common-adapters/emoji'

import type {Props} from './input'

type State = {
  emojiPickerOpen: boolean,
  text: string,
}

class Conversation extends Component<void, Props, State> {
  _input: any;
  _fileInput: any;
  state: State;

  _setRef = r => {
    this._input = r
  }

  constructor (props: Props) {
    super(props)
    const {emojiPickerOpen} = props
    this.state = {emojiPickerOpen, text: this.props.defaultText}
  }

  componentDidMount () {
    document.body.addEventListener('keydown', this._globalKeyDownHandler)
  }

  componentWillUnmount () {
    document.body.removeEventListener('keydown', this._globalKeyDownHandler)
  }

  componentDidUpdate (prevProps: Props) {
    if (!this.props.isLoading && prevProps.isLoading) {
      this.focusInput()
    }
  }

  _globalKeyDownHandler = (ev: KeyboardEvent) => {
    if (!this._input) {
      return
    }

    const target = ev.target
    if (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement) {
      return
    }

    // Allow copy
    if (ev.metaKey && ['Meta', 'c'].includes(ev.key)) {
      return
    }

    this._input.focus()
  }

  _insertEmoji (emojiColons: string) {
    const text: string = this.state.text || ''
    if (this._input) {
      const {selectionStart = 0, selectionEnd = 0} = this._input.selections() || {}
      const nextText = [text.substring(0, selectionStart), emojiColons, text.substring(selectionEnd)].join('')
      this.setState({text: nextText})
      this.focusInput()
{'fraction_non_alphanumeric': 0.1378431927540334, 'fraction_numerical': 0.002830455703368242, 'mean_word_length': 3.4009962640099625, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '661442', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1102, 'n_words': 259}