<commit_before>import React from 'react';
import ACE from 'brace';
import i18n from 'i18next-client';

import 'brace/mode/html';
import 'brace/mode/css';
import 'brace/mode/javascript';
import 'brace/theme/monokai';

class Editor extends React.Component {
  componentWillReceiveProps(nextProps) {
    if (nextProps.projectKey !== this.props.projectKey) {
      this._startNewSession(nextProps.source);
    } else if (nextProps.source !== this._editor.getValue()) {
      this._editor.setValue(nextProps.source);
    }

    this._editor.getSession().setAnnotations(nextProps.errors);
  }

  shouldComponentUpdate() {
    return false;
  }

  componentWillUnmount() {
    this._editor.destroy();
  }

  _jumpToLine(line, column) {
    this._editor.moveCursorTo(line, column);
    this._editor.focus();
  }

  _setupEditor(containerElement) {
    if (containerElement) {
      this._editor = ACE.edit(containerElement);
      this._editor.$blockScrolling = Infinity;
      this._configureSession(this._editor.getSession());
      this._disableAutoClosing();
      this._editor.resize();
      this._editor.on('focus', this._editor.resize.bind(this._editor));
    } else {
      this._editor.destroy();
    }
  }

  _disableAutoClosing() {
    this._editor.setBehavioursEnabled(false);
  }

  _startNewSession(source) {
    const session = new ACE.EditSession(source);
    this._configureSession(session);
    this._editor.setSession(session);
    this._editor.moveCursorTo(0, 0);
    this._editor.resize();
  }

  _configureSession(session) {
    const language = this.props.language;
    session.setUseWrapMode(true);
    session.setUseWorker(false);
    session.setMode(`ace/mode/${language}`);
    session.on('change', () => {
      this.props.onInput(this._editor.getValue());
    });
    session.setAnnotations(this.props.errors);
  }

  _renderLabel() {
    return (
      <div
        className="editors-editorContainer-label"<commit_msg>Use createEditSession<commit_after>import React from 'react';
import ACE from 'brace';
import i18n from 'i18next-client';

import 'brace/mode/html';
import 'brace/mode/css';
import 'brace/mode/javascript';
import 'brace/theme/monokai';

class Editor extends React.Component {
  componentWillReceiveProps(nextProps) {
    if (nextProps.projectKey !== this.props.projectKey) {
      this._startNewSession(nextProps.source);
    } else if (nextProps.source !== this._editor.getValue()) {
      this._editor.setValue(nextProps.source);
    }

    this._editor.getSession().setAnnotations(nextProps.errors);
  }

  shouldComponentUpdate() {
    return false;
  }

  componentWillUnmount() {
    this._editor.destroy();
  }

  _jumpToLine(line, column) {
    this._editor.moveCursorTo(line, column);
    this._editor.focus();
  }

  _setupEditor(containerElement) {
    if (containerElement) {
      this._editor = ACE.edit(containerElement);
      this._editor.$blockScrolling = Infinity;
      this._configureSession(this._editor.getSession());
      this._disableAutoClosing();
      this._editor.resize();
      this._editor.on('focus', this._editor.resize.bind(this._editor));
    } else {
      this._editor.destroy();
    }
  }

  _disableAutoClosing() {
    this._editor.setBehavioursEnabled(false);
  }

  _startNewSession(source) {
    const language = this.props.language;
    const session = ACE.createEditSession(source, `ace/mode/${language}`);
    this._configureSession(session);
    this._editor.setSession(session);
    this._editor.moveCursorTo(0, 0);
    this._editor.resize();
  }

  _configureSession(session) {
    const language = this.props.language;
    session.setUseWrapMode(true);
    session.setUseWorker(false);
    session.setMode(`ace/mode/${language}`);
    session.on('change', () => {
      this.props.onInput(this._editor.getValue());
    });
    session.setAnnotations(this.props.errors);
  }

  _renderLabel() {
    return (
      <div
        className="editors-editorContainer-label"
{'fraction_non_alphanumeric': 0.1398989898989899, 'fraction_numerical': 0.0030303030303030303, 'mean_word_length': 3.682033096926714, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5077971', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1208, 'n_words': 173}