Closed hesiman closed 5 years ago
I have implemented it by codemirror
import {PureComponent} from 'react'
import CodeMirror from 'codemirror/lib/codemirror'
require('codemirror/lib/codemirror.css');
require('codemirror/theme/eclipse.css')
require('codemirror/theme/neat.css')
require('codemirror/addon/lint/lint.css')
require('codemirror/addon/merge/merge.css')
require('codemirror/mode/javascript/javascript')
require('codemirror/addon/lint/lint')
require('codemirror/addon/lint/javascript-lint')
require('codemirror/addon/merge/merge')
if(!window.JSHINT) window.JSHINT = require('jshint').JSHINT
class MergeCodeTextArea extends PureComponent{
constructor(props){
super(props)
this.state = {
value: {
val: '',
orig: ''
}
}
}
componentDidMount(){
const {value:{val,orig}} = this.state;
const {language='javascript',theme="eclipse",lineNumbers=true} = this.props
const dv = CodeMirror.MergeView(this._ref, {
theme: theme,
value: val,
origLeft: null,
origRight: orig,
allowEditingOriginals: true,
lineNumbers: lineNumbers,
mode: language,
highlightDifferences: true,
gutters: ['CodeMirror-lint-markers'],
lint: true,
connect: 'align'
})
}
render(){
return (
<div ref={ref=>this._ref=ref}>
</div>
)
}
}
export default MergeCodeTextArea
getting this ReferenceError: diff_match_patch is not defined
getting this
ReferenceError: diff_match_patch is not defined
me too, have you solved it?
Either adding the script in your window:
<script src="https://cdnjs.cloudflare.com/ajax/libs/diff_match_patch/20121119/diff_match_patch.js"></script>
OR in node:
const DMP = require('diff_match_patch');
Object.keys(DMP).forEach((key) => { window[key] = DMP[key]; });
I am not getting any MergeView from CodeMirror component Can you provide an example in functional component using react-codemirror2?
hi,first, thanks for react-codemirror2
There's a codemirror merge demo on the official website. https://codemirror.net/demo/merge.html#
I have tried to apply the configuration like the demo in the options, But it didn't work. Is this application supported?