| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import React from 'react';
- import PropTypes from 'prop-types';
- import { UnControlled as CodeMirror } from 'react-codemirror2';
- require('codemirror/lib/codemirror.css');
- require('codemirror/addon/display/autorefresh');
- require('codemirror/addon/edit/matchbrackets');
- require('codemirror/addon/edit/matchtags');
- require('codemirror/addon/edit/closetag');
- require('codemirror/addon/edit/continuelist');
- require('codemirror/addon/edit/indentlist');
- require('codemirror/addon/search/match-highlighter');
- require('codemirror/addon/scroll/annotatescrollbar');
- require('codemirror/mode/gfm/gfm');
- require('codemirror/theme/eclipse.css');
- export default class Editor extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- value: this.props.value,
- };
- }
- render() {
- return (
- <CodeMirror
- value={this.state.value}
- autoFocus={true}
- options={{
- mode: 'gfm',
- theme: 'eclipse',
- lineNumbers: true,
- tabSize: 4,
- indentUnit: 4,
- lineWrapping: true,
- autoRefresh: true,
- autoCloseTags: true,
- matchBrackets: true,
- matchTags: {bothTags: true},
- // match-highlighter, matchesonscrollbar, annotatescrollbar options
- highlightSelectionMatches: {annotateScrollbar: true},
- // markdown mode options
- highlightFormatting: true,
- // continuelist, indentlist
- extraKeys: {
- "Enter": "newlineAndIndentContinueMarkdownList",
- "Tab": "autoIndentMarkdownList",
- "Shift-Tab": "autoUnindentMarkdownList"
- }
- }}
- onScroll={(editor, data) => {
- if (this.props.onScroll != null) {
- this.props.onScroll(editor, data);
- }
- }}
- onChange={(editor, data, value) => {
- if (this.props.onChange != null) {
- this.props.onChange(value);
- }
- }}
- />
- )
- }
- }
- Editor.propTypes = {
- value: PropTypes.string,
- onChange: PropTypes.func,
- onScroll: PropTypes.func,
- };
|