import React from 'react' import CodeEditor from 'browser/components/CodeEditor' import MarkdownPreview from 'browser/components/MarkdownPreview' import { findStorage } from 'browser/lib/findStorage' import styles from './MarkdownSplitEditor.styl' import CSSModules from 'browser/lib/CSSModules' class MarkdownSplitEditor extends React.Component { constructor (props) { super(props) this.state = { value: props.value } this.value = props.value this.focus = () => this.refs.code.focus() this.reload = () => this.refs.code.reload() } componentWillReceiveProps (props) { this.setState({ value: props.value }) } handleOnChange (e) { const value = this.refs.code.value this.setState({ value }, () => { this.value = value this.props.onChange() }) } handleCheckboxClick (e) { e.preventDefault() e.stopPropagation() const idMatch = /checkbox-([0-9]+)/ const checkedMatch = /\[x\]/i const uncheckedMatch = /\[ \]/ if (idMatch.test(e.target.getAttribute('id'))) { const lineIndex = parseInt(e.target.getAttribute('id').match(idMatch)[1], 10) - 1 const lines = this.refs.code.value .split('\n') const targetLine = lines[lineIndex] if (targetLine.match(checkedMatch)) { lines[lineIndex] = targetLine.replace(checkedMatch, '[ ]') } if (targetLine.match(uncheckedMatch)) { lines[lineIndex] = targetLine.replace(uncheckedMatch, '[x]') } this.refs.code.setValue(lines.join('\n')) } } render () { const { config, storageKey } = this.props const { value } = this.state const storage = findStorage(storageKey) const previewStyle = {} if (this.props.ignorePreviewPointerEvents) previewStyle.pointerEvents = 'none' return (