<commit_before>import _ from 'underscore';
import CodeMirror from 'codemirror';
import Field from '../Field';
import React from 'react';
import ReactDOM from 'react-dom';
import { FormInput } from 'elemental';
import classnames from 'classnames';

/**
 * TODO:
 * - Remove dependency on underscore
 */

// See CodeMirror docs for API:
// http://codemirror.net/doc/manual.html

module.exports = Field.create({

	displayName: 'CodeField',

	getInitialState () {
		return {
			isFocused: false
		};
	},

	componentDidMount () {
		if (!this.refs.codemirror) {
			return;
		}

		var options = _.defaults({}, this.props.editor, {
			lineNumbers: true,
			readOnly: this.shouldRenderField() ? false : true
		});

		this.codeMirror = CodeMirror.fromTextArea(ReactDOM.findDOMNode(this.refs.codemirror), options);
		this.codeMirror.setSize(undefined, this.props.height);
		this.codeMirror.on('change', this.codemirrorValueChanged);
		this.codeMirror.on('focus', this.focusChanged.bind(this, true));
		this.codeMirror.on('blur', this.focusChanged.bind(this, false));
		this._currentCodemirrorValue = this.props.value;
	},

	componentWillUnmount () {
		// todo: is there a lighter-weight way to remove the cm instance?
		if (this.codeMirror) {
			this.codeMirror.toTextArea();
		}
	},

	componentWillReceiveProps (nextProps) {
		if (this.codeMirror && this._currentCodemirrorValue !== nextProps.value) {
			this.codeMirror.setValue(nextProps.value);
		}
	},

	focus () {
		if (this.codeMirror) {
			this.codeMirror.focus();
		}
	},

	focusChanged (focused) {
		this.setState({<commit_msg>Change indicating width not to be changed when setting height of CodeMirror instance  in CodeField to comply with its documentation<commit_after>import _ from 'underscore';
import CodeMirror from 'codemirror';
import Field from '../Field';
import React from 'react';
import ReactDOM from 'react-dom';
import { FormInput } from 'elemental';
import classnames from 'classnames';

/**
 * TODO:
 * - Remove dependency on underscore
 */

// See CodeMirror docs for API:
// http://codemirror.net/doc/manual.html

module.exports = Field.create({

	displayName: 'CodeField',

	getInitialState () {
		return {
			isFocused: false
		};
	},

	componentDidMount () {
		if (!this.refs.codemirror) {
			return;
		}

		var options = _.defaults({}, this.props.editor, {
			lineNumbers: true,
			readOnly: this.shouldRenderField() ? false : true
		});

		this.codeMirror = CodeMirror.fromTextArea(ReactDOM.findDOMNode(this.refs.codemirror), options);
		this.codeMirror.setSize(null, this.props.height);
		this.codeMirror.on('change', this.codemirrorValueChanged);
		this.codeMirror.on('focus', this.focusChanged.bind(this, true));
		this.codeMirror.on('blur', this.focusChanged.bind(this, false));
		this._currentCodemirrorValue = this.props.value;
	},

	componentWillUnmount () {
		// todo: is there a lighter-weight way to remove the cm instance?
		if (this.codeMirror) {
			this.codeMirror.toTextArea();
		}
	},

	componentWillReceiveProps (nextProps) {
		if (this.codeMirror && this._currentCodemirrorValue !== nextProps.value) {
			this.codeMirror.setValue(nextProps.value);
		}
	},

	focus () {
		if (this.codeMirror) {
			this.codeMirror.focus();
		}
	},

	focusChanged (focused) {
		this.setState({
{'fraction_non_alphanumeric': 0.13905053598774886, 'fraction_numerical': 0.0, 'mean_word_length': 4.242375601926164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4415344', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1050, 'n_words': 226}