@@ -30,6 +30,7 @@ module.exports = React.createClass({
3030 editor . renderer . setShowGutter ( true )
3131 editor . setTheme ( 'ace/theme/xcode' )
3232 editor . clearSelection ( )
33+ editor . moveCursorTo ( 0 , 0 )
3334
3435 editor . setReadOnly ( ! ! this . props . readOnly )
3536
@@ -50,23 +51,33 @@ module.exports = React.createClass({
5051 this . props . onChange ( e , value )
5152 }
5253 } . bind ( this ) )
53-
54- this . setState ( { editor : editor } )
5554 } ,
5655 componentDidUpdate : function ( prevProps ) {
57- if ( this . state . editor . getValue ( ) !== this . props . code ) {
58- this . state . editor . setValue ( this . props . code )
59- this . state . editor . clearSelection ( )
56+ if ( this . editor . getValue ( ) !== this . props . code ) {
57+ this . editor . setValue ( this . props . code )
58+ this . editor . clearSelection ( )
6059 }
6160 if ( prevProps . mode !== this . props . mode ) {
62- var session = this . state . editor . getSession ( )
61+ var session = this . editor . getSession ( )
6362 let mode = _ . findWhere ( modes , { name : this . props . mode } )
6463 let syntaxMode = mode != null
6564 ? mode . mode
6665 : 'text'
6766 session . setMode ( 'ace/mode/' + syntaxMode )
6867 }
6968 } ,
69+ getFirstVisibleRow : function ( ) {
70+ return this . editor . getFirstVisibleRow ( )
71+ } ,
72+ getCursorPosition : function ( ) {
73+ return this . editor . getCursorPosition ( )
74+ } ,
75+ moveCursorTo : function ( row , col ) {
76+ this . editor . moveCursorTo ( row , col )
77+ } ,
78+ scrollToLine : function ( num ) {
79+ this . editor . scrollToLine ( num , false , false )
80+ } ,
7081 render : function ( ) {
7182 return (
7283 < div ref = 'target' className = { this . props . className == null ? 'CodeEditor' : 'CodeEditor ' + this . props . className } > </ div >
0 commit comments