<commit_before>var tinymce = require('tinymce'),
	React = require('react'),
	Field = require('../Field'),
	_ = require('underscore');

var lastId = 0;

function getId() {
	return 'keystone-html-' + lastId++;
}

module.exports = Field.create({
	
	displayName: 'HtmlField',
	
	getInitialState: function() {
		return {
			id: getId(),
			isFocused: false
		};
	},

	initWysiwyg: function() {
		if (!this.props.wysiwyg) return;

		var self = this;
		var opts = this.getOptions();

		opts.setup = function (editor) {
			self.editor = editor;
			editor.on('change', self.valueChanged);
			editor.on('focus', self.focusChanged.bind(self, true));
			editor.on('blur', self.focusChanged.bind(self, false));
		};

		this._currentValue = this.props.value;
		tinymce.init(opts);
	},

	componentDidUpdate: function(prevProps, prevState) {
		if(prevState.isCollapsed && !this.state.isCollapsed) {
			this.initWysiwyg();
		}
	},

	componentDidMount: function() {
		this.initWysiwyg();
	},
	
	componentWillReceiveProps: function(nextProps) {
		if (this.editor && this._currentValue !== nextProps.value) {
			this.editor.setContent(nextProps.value);
		}
	},
	<commit_msg>Code formatting<commit_after>var tinymce = require('tinymce'),
	React = require('react'),
	Field = require('../Field'),
	_ = require('underscore');

var lastId = 0;

function getId() {
	return 'keystone-html-' + lastId++;
}

module.exports = Field.create({
	
	displayName: 'HtmlField',
	
	getInitialState: function() {
		return {
			id: getId(),
			isFocused: false
		};
	},

	initWysiwyg: function() {
		if (!this.props.wysiwyg) return;

		var self = this;
		var opts = this.getOptions();

		opts.setup = function (editor) {
			self.editor = editor;
			editor.on('change', self.valueChanged);
			editor.on('focus', self.focusChanged.bind(self, true));
			editor.on('blur', self.focusChanged.bind(self, false));
		};

		this._currentValue = this.props.value;
		tinymce.init(opts);
	},

	componentDidUpdate: function(prevProps, prevState) {
		if (prevState.isCollapsed && !this.state.isCollapsed) {
			this.initWysiwyg();
		}
	},

	componentDidMount: function() {
		this.initWysiwyg();
	},
	
	componentWillReceiveProps: function(nextProps) {
		if (this.editor && this._currentValue !== nextProps.value) {
			this.editor.setContent(nextProps.value);
		}
	},
	
{'fraction_non_alphanumeric': 0.16616183470359153, 'fraction_numerical': 0.0008654262224145391, 'mean_word_length': 4.126385809312638, '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': '7634561', 'n_tokens_mistral': 897, 'n_tokens_neox': 796, 'n_words': 142}