@@ -104,6 +104,7 @@ class Editor extends React.Component {
104104 this . showFind = this . showFind . bind ( this ) ;
105105 this . showReplace = this . showReplace . bind ( this ) ;
106106 this . getContent = this . getContent . bind ( this ) ;
107+ this . updateFileContent = this . updateFileContent . bind ( this ) ;
107108 }
108109
109110 componentDidMount ( ) {
@@ -220,7 +221,8 @@ class Editor extends React.Component {
220221 tidyCode : this . tidyCode ,
221222 showFind : this . showFind ,
222223 showReplace : this . showReplace ,
223- getContent : this . getContent
224+ getContent : this . getContent ,
225+ updateFileContent : this . updateFileContent
224226 } ) ;
225227 }
226228
@@ -254,6 +256,9 @@ class Editor extends React.Component {
254256 if ( ! prevProps . unsavedChanges ) {
255257 setTimeout ( ( ) => this . props . setUnsavedChanges ( false ) , 400 ) ;
256258 }
259+ } else if ( this . getContent ( ) . content !== this . props . file . content ) {
260+ // TODO: make this not break regular edits!
261+ // this._cm.setValue(this.props.file.content);
257262 }
258263 if ( this . props . fontSize !== prevProps . fontSize ) {
259264 this . _cm . getWrapperElement ( ) . style [
@@ -329,7 +334,8 @@ class Editor extends React.Component {
329334 tidyCode : this . tidyCode ,
330335 showFind : this . showFind ,
331336 showReplace : this . showReplace ,
332- getContent : this . getContent
337+ getContent : this . getContent ,
338+ updateFileContent : this . updateFileContent
333339 } ) ;
334340 }
335341
@@ -366,6 +372,16 @@ class Editor extends React.Component {
366372 return updatedFile ;
367373 }
368374
375+ updateFileContent ( id , src ) {
376+ const file = this . _docs [ id ] ;
377+ if ( file ) {
378+ this . _docs [ id ] = CodeMirror . Doc ( src , this . _docs [ id ] . modeOption ) ;
379+ if ( id === this . props . file . id ) {
380+ this . _cm . swapDoc ( this . _docs [ id ] ) ;
381+ }
382+ }
383+ }
384+
369385 handleKeyUp = ( ) => {
370386 const lineNumber = parseInt ( this . _cm . getCursor ( ) . line + 1 , 10 ) ;
371387 this . setState ( { currentLine : lineNumber } ) ;
0 commit comments