11'use strict' ; 
22
33var  React  =  require ( 'react' ) ; 
4+ var  ReactDOM  =  require ( 'react-dom-polyfill' ) ( React ) ; 
5+ var  findDOMNode  =  ReactDOM . findDOMNode ; 
46var  className  =  require ( 'classnames' ) ; 
57var  debounce  =  require ( 'lodash.debounce' ) ; 
68
@@ -10,11 +12,12 @@ var CodeMirror = React.createClass({
1012	propTypes : { 
1113		onChange : React . PropTypes . func , 
1214		onFocusChange : React . PropTypes . func , 
15+ 		onScroll : React . PropTypes . func , 
1316		options : React . PropTypes . object , 
1417		path : React . PropTypes . string , 
1518		value : React . PropTypes . string , 
1619		className : React . PropTypes . any , 
17- 		codeMirrorInstance : React . PropTypes . object 
20+ 		codeMirrorInstance : React . PropTypes . func 
1821	} , 
1922	getCodeMirrorInstance : function  getCodeMirrorInstance ( )  { 
2023		return  this . props . codeMirrorInstance  ||  require ( 'codemirror' ) ; 
@@ -25,12 +28,13 @@ var CodeMirror = React.createClass({
2528		} ; 
2629	} , 
2730	componentDidMount : function  componentDidMount ( )  { 
28- 		var  textareaNode  =  this . refs . textarea ; 
31+ 		var  textareaNode  =  findDOMNode ( this . refs . textarea ) ; 
2932		var  codeMirrorInstance  =  this . getCodeMirrorInstance ( ) ; 
3033		this . codeMirror  =  codeMirrorInstance . fromTextArea ( textareaNode ,  this . props . options ) ; 
3134		this . codeMirror . on ( 'change' ,  this . codemirrorValueChanged ) ; 
3235		this . codeMirror . on ( 'focus' ,  this . focusChanged . bind ( this ,  true ) ) ; 
3336		this . codeMirror . on ( 'blur' ,  this . focusChanged . bind ( this ,  false ) ) ; 
37+ 		this . codeMirror . on ( 'scroll' ,  this . scrollChanged ) ; 
3438		this . codeMirror . setValue ( this . props . defaultValue  ||  this . props . value  ||  '' ) ; 
3539	} , 
3640	componentWillUnmount : function  componentWillUnmount ( )  { 
@@ -65,6 +69,9 @@ var CodeMirror = React.createClass({
6569		} ) ; 
6670		this . props . onFocusChange  &&  this . props . onFocusChange ( focused ) ; 
6771	} , 
72+ 	scrollChanged : function  scrollChanged ( cm )  { 
73+ 		this . props . onScroll  &&  this . props . onScroll ( cm . getScrollInfo ( ) ) ; 
74+ 	} , 
6875	codemirrorValueChanged : function  codemirrorValueChanged ( doc ,  change )  { 
6976		if  ( this . props . onChange  &&  change . origin  !=  'setValue' )  { 
7077			this . props . onChange ( doc . getValue ( ) ) ; 
0 commit comments