<commit_before>import React from 'react';
import ReactDOM from 'react-dom';

import CodeMirror from 'react-code-mirror';

import { updateCellSource } from '../../actions';

export default class Editor extends React.Component {
  static propTypes = {
    id: React.PropTypes.string,
    input: React.PropTypes.any,
    language: React.PropTypes.string,
    lineNumbers: React.PropTypes.bool,
    onChange: React.PropTypes.func,
    theme: React.PropTypes.string,
  };

  static contextTypes = {
    dispatch: React.PropTypes.func,
  };

  static defaultProps = {
    language: 'python',
    lineNumbers: false,
    text: '',
    theme: 'composition',
  };

  constructor(props) {
    super(props);
    this.state = {
      source: this.props.input,
    };
  }

  componentDidMount() {
    const editor = ReactDOM.findDOMNode(this.refs.codemirror);
    editor.addEventListener('keypress', (e) => {
      if (e.keyCode === 13 && e.shiftKey) {
        e.preventDefault();
      }
    });
  }

  componentWillReceiveProps(nextProps) {
    this.setState({
      source: nextProps.input,
    });
  }

  render() {
    return (
      <div className='cell_editor'>
        <CodeMirror value={this.state.source}
                    ref='codemirror'
                    className='cell_cm'
                    mode={this.props.language}
                    textAreaClassName={['editor']}
                    textAreaStyle={{
                      minHeight: '10em',
                      backgroundColor: 'red',
                    }}
                    lineNumbers={this.props.lineNumbers}
                    theme={this.props.theme}
                    onChange={
                      (e) => {
                        if (this.props.onChange) {
                          this.props.onChange(e.target.value);
                        } else {
                          this.setState({
                            source: e.target.value,
                          });
                          this.context.dispatch(updateCellSource(this.props.id, e.target.value));
                        }
                      }
                    }/>
      </div>
    );<commit_msg>Clean up our editor component.<commit_after>import React from 'react';
import ReactDOM from 'react-dom';

import CodeMirror from 'react-code-mirror';

import { updateCellSource } from '../../actions';

export default class Editor extends React.Component {
  static propTypes = {
    id: React.PropTypes.string,
    input: React.PropTypes.any,
    language: React.PropTypes.string,
    lineNumbers: React.PropTypes.bool,
    onChange: React.PropTypes.func,
    theme: React.PropTypes.string,
  };

  static contextTypes = {
    dispatch: React.PropTypes.func,
  };

  static defaultProps = {
    language: 'python',
    lineNumbers: false,
    text: '',
    theme: 'composition',
  };

  constructor(props) {
    super(props);
    this.state = {
      source: this.props.input,
    };

    this.onChange = this.onChange.bind(this);
  }

  componentDidMount() {
    const editor = ReactDOM.findDOMNode(this.refs.codemirror);
    editor.addEventListener('keypress', (e) => {
      if (e.keyCode === 13 && e.shiftKey) {
        e.preventDefault();
      }
    });
  }

  componentWillReceiveProps(nextProps) {
    this.setState({
      source: nextProps.input,
    });
  }

  onChange(e) {
    if (this.props.onChange) {
      this.props.onChange(e.target.value);
    } else {
      this.setState({
        source: e.target.value,
      });
      this.context.dispatch(updateCellSource(this.props.id, e.target.value));
    }
  }

  render() {
    return (
      <div className="cell_editor">
        <CodeMirror
          value={this.state.source}
          ref="codemirror"
          className="cell_cm"
          mode={this.props.language}
          textAreaClassName={['editor']}
          textAreaStyle={{
            minHeight: '10em',
            backgroundColor: 'red',
          }}
          lineNumbers={this.props.lineNumbers}
          theme={this.props.theme}
          onChange={this.onChange}
        />
      </div>
    );
{'fraction_non_alphanumeric': 0.1282051282051282, 'fraction_numerical': 0.0019536019536019536, 'mean_word_length': 1.8523676880222841, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, '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': '4501137', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1162, 'n_words': 202}