Advertisement
Guest User

Untitled

a guest
May 26th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. import React from 'react';
  2. import CodeMirror from 'codemirror';
  3. import 'codemirror/mode/javascript/javascript';
  4. import 'codemirror/addon/selection/active-line'
  5. import 'codemirror/keymap/vim'
  6.  
  7. class Editor extends React.Component {
  8. _cm: CodeMirror.Editor
  9.  
  10. componentDidMount() {
  11. this._cm = CodeMirror(this.refs.container, {
  12. theme: 'p5-widget',
  13. value: this.props.content,
  14. lineNumbers: true,
  15. styleActiveLine: true,
  16. mode: 'javascript',
  17. keyMap: 'vim'
  18. });
  19. this._cm.on('change', () => {
  20. this.props.updateFile("sketch.js", this._cm.getValue());
  21. });
  22. }
  23.  
  24. componentDidUpdate(prevProps) {
  25. if (this.props.content !== prevProps.content &&
  26. this.props.content !== this._cm.getValue()) {
  27. this._cm.setValue(this.props.content);
  28. }
  29. }
  30.  
  31. componentWillUnmount() {
  32. this._cm = null;
  33. }
  34.  
  35. render() {
  36. return <div ref="container" className="editor-holder"></div>;
  37. }
  38. }
  39.  
  40. export default Editor;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement