@@ -104,6 +104,7 @@ class Editor extends React.Component {
104
104
this . showFind = this . showFind . bind ( this ) ;
105
105
this . showReplace = this . showReplace . bind ( this ) ;
106
106
this . getContent = this . getContent . bind ( this ) ;
107
+ this . updateFileContent = this . updateFileContent . bind ( this ) ;
107
108
}
108
109
109
110
componentDidMount ( ) {
@@ -220,7 +221,8 @@ class Editor extends React.Component {
220
221
tidyCode : this . tidyCode ,
221
222
showFind : this . showFind ,
222
223
showReplace : this . showReplace ,
223
- getContent : this . getContent
224
+ getContent : this . getContent ,
225
+ updateFileContent : this . updateFileContent
224
226
} ) ;
225
227
}
226
228
@@ -254,6 +256,9 @@ class Editor extends React.Component {
254
256
if ( ! prevProps . unsavedChanges ) {
255
257
setTimeout ( ( ) => this . props . setUnsavedChanges ( false ) , 400 ) ;
256
258
}
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);
257
262
}
258
263
if ( this . props . fontSize !== prevProps . fontSize ) {
259
264
this . _cm . getWrapperElement ( ) . style [
@@ -329,7 +334,8 @@ class Editor extends React.Component {
329
334
tidyCode : this . tidyCode ,
330
335
showFind : this . showFind ,
331
336
showReplace : this . showReplace ,
332
- getContent : this . getContent
337
+ getContent : this . getContent ,
338
+ updateFileContent : this . updateFileContent
333
339
} ) ;
334
340
}
335
341
@@ -366,6 +372,16 @@ class Editor extends React.Component {
366
372
return updatedFile ;
367
373
}
368
374
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
+
369
385
handleKeyUp = ( ) => {
370
386
const lineNumber = parseInt ( this . _cm . getCursor ( ) . line + 1 , 10 ) ;
371
387
this . setState ( { currentLine : lineNumber } ) ;
0 commit comments