import CodeMirror from "codemirror"; import React from "react"; class CodeMirrorPanel extends React.Component { constructor() { super(); this._textareaRef = React.createRef(); this._codeMirror = null; this.handleChange = this.handleChange.bind(this); } componentDidMount() { this._codeMirror = CodeMirror.fromTextArea( this._textareaRef.current, this.props.options ); this._codeMirror.on("change", this.handleChange); this._codeMirror.setValue(this.props.value || ""); } componentWillUnmount() { this._codeMirror && this._codeMirror.toTextArea(); } componentDidUpdate() { if (this.props.value !== this._codeMirror.getValue()) { this._codeMirror.setValue(this.props.value); } } handleChange(doc, change) { if (change.origin !== "setValue") { this.props.onChange(doc.getValue()); } } render() { return (